"print(x.sort())" prints out "None"


#1

How come the following prints out “None”?

### Exercise 1 & 2 ###
addresses = ['221 B Baker St.', '42 Wallaby Way', '12 Grimmauld Place', '742 Evergreen Terrace', '1600 Pennsylvania Ave', '10 Downing St.']

# Sort addresses here:
sorted_addresses = addresses.sort()

print(sorted_addresses)

Course: Sorting Lists I

edit: topic can be deleted as i already found out what i was missing


#2

for the people running into the same problem: .sort() modifies the list directly and returns None


#3

If you would like to leave the addresses list in its original order and assign a sorted version of it to sorted_addresses, use the sorted built in function, as follows …

sorted_addresses = sorted(addresses)

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.