FAQ: Working with Lists in Python - Sorting Lists I

This community-built FAQ covers the “Sorting Lists I” exercise from the lesson “Working with Lists in Python”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science
Data Science

FAQs on the exercise Sorting Lists I

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

1 Like

2 posts were split to a new topic: Why does this code print none?

6 posts were merged into an existing topic: Why does this code print none?

6 posts were split to a new topic: What is the method of order for sorting the addresses?

5 posts were split to a new topic: How can I sort a zipped object?

How do I save the previous order of the list? I tried it with another variable, that one was sorted too though.
### Exercise 4 ###
cities = ['London', 'Paris', 'Rome', 'Los Angeles', 'New York']
cities.sort() #This returns nothing.
sorted_cities = cities
print(unsorted_cities) #huh.. this is sorted too.

is it because it is like in C, just a pointer that points to the same address?

Yes, both variable point to the same list in memory.

also, .sort() orders the list in place/memory.