0
0
Pythonprogramming~5 mins

Sorting and reversing lists in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Alist.sorted()
Bsorted(list)
Clist.reverse()
Dlist.sort()
What does list.reverse() do?
AReverses the list in place
BReturns a new reversed list
CSorts the list in ascending order
DSorts the list in descending order
How do you get a new sorted list without changing the original?
Alist.reverse()
Blist.sort()
Csorted(list)
Dlist.sorted()
Which argument sorts a list in descending order?
Areverse=False
Breverse=True
Cdescending=True
Dorder='desc'
What is the result of calling list.reverse() twice?
AList returns to original order
BList is sorted descending
CList is empty
DList is sorted ascending
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.