Recall & Review
beginner
What does the
list.sort() method do in Python?It sorts the list in place, changing the original list to be in ascending order by default.
Click to reveal answer
beginner
How do you reverse the order of elements in a list in Python?
You can use the
list.reverse() method to reverse the list in place, or use slicing like list[::-1] to get a reversed copy.Click to reveal answer
intermediate
What is the difference between
sorted(list) and list.sort()?sorted(list) returns a new sorted list and leaves the original unchanged. list.sort() sorts the list in place and returns None.Click to reveal answer
beginner
How can you sort a list in descending order?
Use
list.sort(reverse=True) or sorted(list, reverse=True) to sort the list from highest to lowest.Click to reveal answer
intermediate
What happens if you call
list.reverse() twice on the same list?The list will return to its original order because reversing twice cancels out the first reversal.
Click to reveal answer
Which method sorts a list in place in Python?
✗ Incorrect
list.sort() sorts the list in place. sorted(list) returns a new sorted list.What does
list.reverse() do?✗ Incorrect
list.reverse() reverses the order of elements in the list in place.How do you get a new sorted list without changing the original?
✗ Incorrect
sorted(list) returns a new sorted list and leaves the original unchanged.Which argument sorts a list in descending order?
✗ Incorrect
Use
reverse=True to sort in descending order.What is the result of calling
list.reverse() twice?✗ Incorrect
Reversing twice returns the list to its original order.
Explain how to sort a list and then reverse it in Python.
Think about using two methods one after the other.
You got /4 concepts.
Describe the difference between
sorted() and list.sort().One changes the original list, the other does not.
You got /4 concepts.