如何拆分每行的列表列表?
list = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]
进入:
a b c
d e f
g h i
如何拆分每行的列表列表?
list = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]
进入:
a b c
d e f
g h i
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
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
myList = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']]
for subList in myList:
print " ".join(subList)
(注意——不要使用保留字如list
orstr
来命名你的变量。这迟早会咬你)