redaktroll
redaktroll

Reputation: 63

Write multiple lists to a file with tabs between items and newlines between lists

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

Answers (1)

Mikhail Gerasimov
Mikhail Gerasimov

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

Related Questions