Python - 嵌套分隔文件的嵌套列表?

Dar*_*ick 7 python nested list tab-delimited

我有一个嵌套列表,包含~30,000个子列表,每个子列表有三个条目,例如,

nested_list = [['x', 'y', 'z'], ['a', 'b', 'c']].
Run Code Online (Sandbox Code Playgroud)

我希望创建一个函数,以便将此数据结构输出为制表符分隔格式,例如,

x    y    z
a    b    c
Run Code Online (Sandbox Code Playgroud)

任何帮助非常感谢!

谢谢,Seafoid.

Eli*_*sky 6

>>> nested_list = [['x', 'y', 'z'], ['a', 'b', 'c']]
>>> for line in nested_list:
...   print '\t'.join(line)
... 
x   y   z
a   b   c
>>> 
Run Code Online (Sandbox Code Playgroud)


Sil*_*ost 6

with open('fname', 'w') as file:
    file.writelines('\t'.join(i) + '\n' for i in nested_list)
Run Code Online (Sandbox Code Playgroud)


moj*_*bro 5

在我看来,这是一个简单的单行:

print '\n'.join(['\t'.join(l) for l in nested_list])
Run Code Online (Sandbox Code Playgroud)