Python - Nested List to Tab Delimited File?

Darren J. Fitzpatrick picture Darren J. Fitzpatrick · Mar 24, 2010 · Viewed 12k times · Source

I have a nested list comprising ~30,000 sub-lists, each with three entries, e.g.,

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

I wish to create a function in order to output this data construct into a tab delimited format, e.g.,

x    y    z
a    b    c

Any help greatly appreciated!

Thanks in advance, Seafoid.

Answer

Eli Bendersky picture Eli Bendersky · Mar 24, 2010
>>> nested_list = [['x', 'y', 'z'], ['a', 'b', 'c']]
>>> for line in nested_list:
...   print '\t'.join(line)
... 
x   y   z
a   b   c
>>>