我有一个定义如下的列表:
temp = [[1,2,3,4],5,6]
我正在尝试将temp转换为不包含子列表的列表,如下所示:
temp = [1,2,3,4,5,6]
我试图做到这一点,但出现以下错误:
flat_list = [item for sublist in temp for item in sublist if type(sublist)=='list']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <listcomp>
TypeError: 'int' object is not iterable
请建议如何进行转换!