Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Nested List to Tab Delimited File?

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.

like image 400
Darren J. Fitzpatrick Avatar asked Mar 24 '10 16:03

Darren J. Fitzpatrick


1 Answers

with open('fname', 'w') as file:
    file.writelines('\t'.join(i) + '\n' for i in nested_list)
like image 100
SilentGhost Avatar answered Sep 18 '22 11:09

SilentGhost