What would be the output of executing the following code:
list1 = [True, 1, 0, True, 2, 1, False, 5, 0]
print(sorted(list1))
|
[0, False, 0, True, 1, True, 1, 2, 5]
[0, 0, False, 1, 1, True, True, 2, 5]
[False, 0, 0, True, True, 1, 1, 2, 5]
TypeError
|
Explanation:
In python, False is evaluated as 0 and True as 1. So, first 0, False, 0 are chosen as they are in that order in the original list. Then, True, 1, True, 1 are chosen as they are in that order in the original list. Then, 2 and 5 are obvious choices.
What is the difference between sort and sorted?
|