python output list to txt code example
Example 1: convert python list to text file
# define list of places
places = ['Berlin', 'Cape Town', 'Sydney', 'Moscow']
with open('listfile.txt', 'w') as filehandle:
for listitem in places:
filehandle.write('%s\n' % listitem)
Example 2: list to text file python
with open('your_file.txt', 'w') as f:
for item in my_list:
f.write("%s\n" % item)