我有一个名为 “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”) –