PCEP 3.5 Flashcards
1
Q
use the sort() method to sort elements of a list
A
lst = [5, 3, 1, 2, 4]
print(lst)
lst.sort()
print(lst) # outputs: [1, 2, 3, 4, 5]
2
Q
use the revers method to reverse a list.
A
lst = [5, 3, 1, 2, 4]
print(lst)
lst.reverse()
print(lst) # outputs: [4, 2, 1, 3, 5]
3
Q
What is the output of the following snippet?
lst = [“D”, “F”, “A”, “Z”]
lst.sort()
print(lst)
A
[‘A’, ‘D’’ ‘F’, ‘Z’]
4
Q
a = 3
b = 1
c = 2
lst = [a, c, b]
lst.sort()
print(lst)
A
[1, 2, 3]
5
Q
What is the output of the following snippet?
a = “A”
b = “B”
c = “C”
d = “ “
lst = [a, b, c, d]
lst.reverse()
print(lst)
A
[’ ‘, ‘C’, ‘B’, ‘A”]