Python list comprehension to join list of lists
本问题已经有最佳答案,请猛点这里访问。
以
如何将其转换为单个字符串列表?
1 2 | lists = [['hello'], ['world', 'foo', 'bar']] combined = [item for sublist in lists for item in sublist] |
或: </P >
1 2 3 4 | import itertools lists = [['hello'], ['world', 'foo', 'bar']] combined = list(itertools.chain.from_iterable(lists)) |
1 2 3 4 | from itertools import chain combined = [['hello'], ['world', 'foo', 'bar']] single = [i for i in chain.from_iterable(combined)] |