Recall & Review
beginner
What does the
sorted() function do in Python?The
sorted() function takes any iterable (like a list or tuple) and returns a new list with all the items in ascending order by default.Click to reveal answer
beginner
How do you sort a list in descending order using
sorted()?Use the
reverse=True argument inside sorted(). For example: sorted(my_list, reverse=True) sorts the list from highest to lowest.Click to reveal answer
intermediate
What is the difference between
sorted() and the list method sort()?sorted() returns a new sorted list and works on any iterable. list.sort() changes the original list in place and returns None.Click to reveal answer
intermediate
How can you sort a list of strings ignoring case using
sorted()?Use the
key=str.lower argument to sort strings without case sensitivity. Example: sorted(words, key=str.lower).Click to reveal answer
beginner
What type of object does
sorted() return?sorted() always returns a new list, even if the input is a tuple or other iterable.Click to reveal answer
What will
sorted([3, 1, 2]) return?✗ Incorrect
sorted() returns a new list sorted in ascending order.Which argument sorts a list in descending order?
✗ Incorrect
The correct argument is
reverse=True.What does
sorted() return when given a tuple?✗ Incorrect
sorted() always returns a new list, even if input is a tuple.How do you sort strings ignoring case?
✗ Incorrect
Use
key=str.lower to ignore case while sorting.Which is true about
list.sort() compared to sorted()?✗ Incorrect
list.sort() changes the original list and returns None.Explain how to use the
sorted() function to sort a list in descending order and ignoring case for strings.Think about the arguments <code>reverse</code> and <code>key</code>.
You got /5 concepts.
Describe the difference between
sorted() and list.sort() in Python.Consider what happens to the original list.
You got /4 concepts.