質問

私は、ネストされたリストからなる〜3つのエントリ、例えば30,000サブリスト、それぞれを持っている。

nested_list = [['x', 'y', 'z'], ['a', 'b', 'c']].

私は、タブ区切り形式に出力するために、このデータ構造体を関数を作成したい例えば。、

x    y    z
a    b    c

すべてのヘルプは大歓迎!

事前に

おかげで、 Seafoidます。

役に立ちましたか?

解決

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

他のヒント

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

私の見解では、それは簡単なワンライナーです:

print '\n'.join(['\t'.join(l) for l in nested_list])
>>> print '\n'.join(map('\t'.join,nested_list))
x       y       z
a       b       c
>>>
out = file("yourfile", "w")
for line in nested_list:
    print >> out, "\t".join(line)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top