Reputation: 63
Hi I'm trying to output multiple lists to a file with having each list in a separate line, and each element of the list separated by tab.
with lists being as:
['l1_el1', 'l1_el2', 'l1_el3']
['l2_el1', 'l2_el2', 'l2_el3']
The example of the output should be like:
l1_el1 l1_el2 l1_el3
l2_el1 l2_el2 l2_el3
Upvotes: 0
Views: 1056
Reputation: 39546
lst1 = ['l1_el1', 'l1_el2', 'l1_el3']
lst2 = ['l1_el4', 'l1_el5', 'l1_el6']
with open('file.txt', 'w') as fh:
for l in (lst1, lst2):
fh.write('\t'.join(l) + '\n')
Upvotes: 1