我有一个列表,如下所示:
my_list =
[['UK', 'Manchester City', 'Blue', '1','2','B'],
['ES', 'FC Barcelona', 'Blue', '2','1','C'],
['IT', 'Juventus', 'White', '3','2','A'],
['DE', 'Borussia Dortmund', 'Yellow', '4','1','A']]
现在我想编辑my_list
,并实际删除索引0
、3
、4
和5
中的值
这是我的预期输出:
my_list =
[['Manchester City', 'Blue'],
['FC Barcelona', 'Blue'],
['Juventus', 'White'],
['Borussia Dortmund', 'Yellow']]
这是我尝试的代码:
for list in my_list:
for idx in [0,3,4,5]:
del list[idx]
print(my_list)
这是我得到的输出:
IndexError: list assignment index out of range
试一试
输出
相关问题 更多 >
编程相关推荐