我有一個名爲 「comms_chairs」 一個python列表的結構是這樣的:list.remove在python - 不能識別的命令
[[' Chairwoman Debbie Stabenow ', 'Agriculture:'], [' Chairman Tim Johnson' ',' 'Banking'], [' Chairman Jay Rockefeller ', 'Commerce:'], [' Chairman Jeff Bingaman', 'Energy:']
當我輸入comms_chairs [0],我得到(預期)
[' Chairwoman Debbie Stabenow ', 'Agriculture:']
然而,當我試圖從列表中刪除字符串「董事長」下面的失敗:
>>> type(comms_chairs[0])
<type 'list'>
>>> comms_chairs[0].remove(' Chairwoman')
Traceback (most recent call last):
File "<pyshell#104>", line 1, in <module>
comms_chairs[0].remove(' Chairwoman')
ValueError: list.remove(x): x not in list
同問題,當我不把Chairwoman
之前的空間。這裏發生了什麼?它確定在我看來像Chairwoman
是在comms_chairs[0]
。我的總體目標是刪除所有的Chairwoman
和'主席'字符串,但理解一般列表中的內容可能會有所幫助。如果它不明顯,我是一個Python的完全新手。
你沒有一個只有「主席」的項目...你需要'my_list.remove (「女主席Debbie Stabenow」) –