List Quiz: 05

Python Lists Quiz - Expert Level

Python Lists Quiz - Expert Level

Answer the following expert-level questions about Python lists:

Time Remaining: 10:00

1. What will this code output?

x = [1, 2, 3]
y = x[:]
y[0] = 4
print(x)
A) [1, 2, 3] B) [4, 2, 3] C) [4, 4, 4] D) Error

2. What does this code print?

x = [[0] * 3] * 3
x[0][0] = 1
print(x)
A) [[1, 0, 0], [1, 0, 0], [1, 0, 0]] B) [[1, 0, 0], [0, 0, 0], [0, 0, 0]] C) [[1, 0, 0], [1, 0, 0], [0, 0, 0]] D) Error

3. What does this code output?

x = [1, 2, 3, 4]
y = [a * b for a in x if a % 2 == 0 for b in x if b % 2 == 1]
print(y)
A) [2, 6, 10, 2, 6, 10] B) [2, 6, 10, 4, 12] C) [4, 12, 8, 16] D) [4, 12]

4. What does this code output?

x = [1, 2, 3]
x.extend(x)
print(x)
A) [1, 2, 3, 1, 2, 3] B) [1, 2, 3] C) [1, 1, 1] D) Error

5. What does this code output?

x = [10, 20, 30, 40]
y = x[::-2]
print(y)
A) [10, 30] B) [40, 20] C) [40, 30, 20, 10] D) Error

6. What will this code output?

x = [0, 1, 2]
y = [x] * 3
y[0][0] = 5
print(y)
A) [[5, 1, 2], [5, 1, 2], [5, 1, 2]] B) [[5, 1, 2], [0, 1, 2], [0, 1, 2]] C) [[0, 1, 2], [0, 1, 2], [5, 1, 2]] D) Error

7. What does this code output?

x = [10, 20, 30]
y = x.copy()
y.append(40)
print(x, y)
A) [10, 20, 30, 40] [10, 20, 30, 40] B) [10, 20, 30] [10, 20, 30] C) [10, 20, 30] [10, 20, 30, 40] D) Error

8. What does this code output?

x = [1, 2, 3]
y = [i for i in x if i % 2 == 0]
print(y)
A) [1, 3] B) [2] C) [1, 2, 3] D) []

9. What does this code output?

x = [3, 6, 9]
y = [a + b for a in x for b in range(3)]
print(y)
A) [3, 6, 9, 3, 6, 9, 3, 6, 9] B) [3, 4, 5, 6, 7, 8, 9, 10, 11] C) [6, 12, 18] D) Error

10. What does this code output?

x = [1, 2, 3]
print(sum([i**2 for i in x]))
A) 6 B) 14 C) 36 D) Error