How can I get the results of my print onto new lines? The list being printed is a first name, surname and email address, so I want each one on a new line.
import csv
f = open('attendees1.csv')
csv_f = csv.reader(f)
attendee_details = []
for row in csv_f:
attendee_details.append(row[0:4])
sortedlist =[sorted(attendee_details, key=lambda x:x[0])]
print (sortedlist)
print('\n'.join(map(str, sortedlist)))
This will work for all lists. If the list already consists of strings, the map is not needed.
Since you're using Python 3, you can also do this:
print(*sortedlist, sep='\n')
This unpacks the list and sends each element as an argument to print(), with '\n' as a separator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With