Sorting Flashcards

1
Q

What is the syntax to sort a list in Python?

A

arr.sort()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: using arr.sort() in Python sorts the list in ascending order?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How would we sort a list in descending order in Python?

A

arr.sort(reverse=True)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How would you sort a list of strings in Python?

A

arr.sort()

Will sort by alphabetical order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly