How can I write the following list:
[(8, \'rfa\'), (8, \'acc-raid\'), (7, \'rapidbase\'), (7, \'rcts\'), (7, \'tve-announce\'), (5, \'mysql-im\'), (5, \'teln
For flexibility, for example; if some items in your list contain 3 items, others contain 4 items and others contain 2 items you can do this.
mylst = [(8, 'rfa'), (8, 'acc-raid','thrd-item'), (7, 'rapidbase','thrd-item','fourth-item'),(9, 'tryrt')]
# this function converts the integers to strings with a space at the end
def arrtostr(item):
strr=''
for b in item:
strr+=str(b)+' '
return strr
# now write to your file
with open('list.txt','w+') as doc:
for line in mylst:
doc.write(arrtostr(line)+'\n')
doc.close()
And the output in list.txt
8 rfa
8 acc-raid thrd-item
7 rapidbase thrd-item fourth-item
9 tryrt