Dar*_*ick 7 python nested list tab-delimited
我有一个嵌套列表,包含~30,000个子列表,每个子列表有三个条目,例如,
nested_list = [['x', 'y', 'z'], ['a', 'b', 'c']].
我希望创建一个函数,以便将此数据结构输出为制表符分隔格式,例如,
x    y    z
a    b    c
任何帮助非常感谢!
谢谢,Seafoid.
>>> nested_list = [['x', 'y', 'z'], ['a', 'b', 'c']]
>>> for line in nested_list:
...   print '\t'.join(line)
... 
x   y   z
a   b   c
>>> 
with open('fname', 'w') as file:
    file.writelines('\t'.join(i) + '\n' for i in nested_list)
在我看来,这是一个简单的单行:
print '\n'.join(['\t'.join(l) for l in nested_list])