List Quiz: 08
Advanced Python Lists Quiz
Answer the following advanced questions about Python lists:
Time Remaining: 20:00
1. What will this code output?
x = [1, 2, 3, 4, 5]
print(x[::2])
A) [2, 4]
B) [1, 3, 5]
C) [5, 3, 1]
D) Error
2. What will be the output of this code?
x = [10, 20, 30]
y = [i * 2 for i in x]
print(y[1])
A) 20
B) 40
C) 60
D) Error
3. What does this code output?
x = [5, 3, 1]
y = x.pop(1)
print(x, y)
A) [5, 1], 3
B) [5, 3], 1
C) [5, 1], 5
D) Error
4. What will this code output?
x = [2, 4, 6, 8]
x.insert(2, 5)
print(x)
A) [2, 4, 5, 6, 8]
B) [2, 5, 4, 6, 8]
C) [5, 2, 4, 6, 8]
D) Error
5. What is the output of this code?
x = [1, 2, 3, 4, 5]
y = x[1:4]
print(y)
A) [2, 3, 4]
B) [1, 2, 3]
C) [3, 4, 5]
D) Error
6. What will this code output?
x = [2, 4, 6, 8]
print(sum(x) / len(x))
A) 4.0
B) 5.0
C) 6.0
D) Error
7. What does the following code output?
x = [10, 20, 30]
x.append(x[1] + x[2])
print(x)
A) [10, 20, 30, 50]
B) [10, 30, 40]
C) [50]
D) Error
8. What is the output of this code?
x = [[1, 2], [3, 4]]
print(x[1][1])
A) 2
B) 3
C) 4
D) Error
9. What does this code output?
x = [3, 5, 7]
y = [9, 8, 7]
z = [a + b for a, b in zip(x, y)]
print(z)
A) [3, 5, 7, 9, 8, 7]
B) [12, 13, 14]
C) [21]
D) Error
10. What will this code output?
x = [4, 8, 12, 16]
y = [i // 4 for i in x]
print(y)
A) [1, 2, 3, 4]
B) [1, 2, 3]
C) [1, 2, 3, 4, 5]
D) [1, 2, 3, 4]