Reputation: 61
I have a list like: a = [(a,[1,2,3]),(b,[4,5,6)].
How can I write the above list in a txt file like:
a 1 2 3
b 4 5 6
in a most pythonic way? Thanks
Upvotes: 1
Views: 1305
Reputation: 81594
This should do the trick:
with open('filename', 'w') as f:
for elem in a:
f.write('{} {}\n'.format(elem[0], ' '.join(str(i) for i in elem[1])))
Upvotes: 1