Sorting Flashcards
1
Q
What is the syntax to sort a list in Python?
A
arr.sort()
2
Q
True or False: using arr.sort() in Python sorts the list in ascending order?
A
True
3
Q
How would we sort a list in descending order in Python?
A
arr.sort(reverse=True)
4
Q
How would you sort a list of strings in Python?
A
arr.sort()
Will sort by alphabetical order
5
Q
How would you sort a list of strings by number of letters instead of ascending order in Python?
A
arr.sort(key=lambda x: len(x))