拆分列表列表

voy*_*rsm 2 python

如何拆分每行的列表列表?

list = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]
Run Code Online (Sandbox Code Playgroud)

成:

a b c  
d e f  
g h i
Run Code Online (Sandbox Code Playgroud)

NPE*_*NPE 7

In [11]: lst = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]

In [12]: print('\n'.join(' '.join(l) for l in lst))
a b c
d e f
g h i
Run Code Online (Sandbox Code Playgroud)


Jos*_*mit 5

In [1]: mylist = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]

In [2]: for item in mylist:
   ...:     print ' '.join(item)

a b c
d e f
g h i
Run Code Online (Sandbox Code Playgroud)


phi*_*hag 5

您不想拆分元素,您想要加入它们:

>>> lst = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]
>>> print('\n'.join(' '.join(sublist) for sublist in lst))
a b c
d e f
g h i
Run Code Online (Sandbox Code Playgroud)

请注意,这list是一个变量的可怕名称,因为它掩盖了内置list.因此,我将变量重命名为lst.