有没有办法删除嵌套列表中的元素?
Is there a way to remove an element in a nested list?
我有以下列表:
a = ['hi', ['item1', 'item2']]
我正在尝试使用 a.remove()
从列表中删除第一个元素 'hi' 并遍历内部列表,我必须概括它,因为我将使用更多的这些。但是,我无法得到它。
a = a.remove(a[0])
for each_item in a:
for item in each_item:
print(item)
我想 return
item1
item2
但它反而 returns
'NoneType' object is not iterable
我需要能够概括它。也就是说,我需要能够删除该列表的第一个元素,并能够打印列表列表中的其他元素
有办法吗?
a.remove
不会 return 没有删除值的数组。它 returns None 作为删除项目。
不正确:a = a.remove('hi)
.
正确:a.remove('hi')
我有以下列表:
a = ['hi', ['item1', 'item2']]
我正在尝试使用 a.remove()
从列表中删除第一个元素 'hi' 并遍历内部列表,我必须概括它,因为我将使用更多的这些。但是,我无法得到它。
a = a.remove(a[0])
for each_item in a:
for item in each_item:
print(item)
我想 return
item1
item2
但它反而 returns
'NoneType' object is not iterable
我需要能够概括它。也就是说,我需要能够删除该列表的第一个元素,并能够打印列表列表中的其他元素
有办法吗?
a.remove
不会 return 没有删除值的数组。它 returns None 作为删除项目。
不正确:a = a.remove('hi)
.
正确:a.remove('hi')