How can I write the following list:
JavaScript
x
2
1
[(8, 'rfa'), (8, 'acc-raid'), (7, 'rapidbase'), (7, 'rcts'), (7, 'tve-announce'), (5, 'mysql-im'), (5, 'telnetcpcd'), (5, 'etftp'), (5, 'http-alt')]
2
to a text file with two columns (8 rfa)
and many rows, so that I have something like this:
JavaScript
1
8
1
8 rfa
2
8 acc-raid
3
7 rapidbase
4
7 rcts
5
7 tve-announce
6
5 mysql-im
7
5 telnetcpcd
8
Advertisement
Answer
JavaScript
1
3
1
with open('daemons.txt', 'w') as fp:
2
fp.write('n'.join('%s %s' % x for x in mylist))
3
If you want to use str.format(), replace 2nd line with:
JavaScript
1
2
1
fp.write('n'.join('{} {}'.format(x[0],x[1]) for x in mylist))
2