List Quiz: 06

Python Lists Quiz - Extreme Level

Python Lists Quiz - Extreme Level

Answer the following expert-level questions about Python lists:

Time Remaining: 10:00

1. What does this code output?

x = [i for i in range(5) if i % 2 == 0]
x = [i**2 for i in x]
print(sum(x))
A) 4 B) 10 C) 20 D) 30

2. What does this code output?

x = [lambda i=i: i for i in range(5)]
print([f() for f in x])
A) [0, 1, 2, 3, 4] B) [4, 4, 4, 4, 4] C) Error D) None

3. What will this code output?

x = [[j for j in range(i)] for i in range(3, 6)]
print(x)
A) [[0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]] B) [[0, 1, 2], [0, 1, 2], [0, 1, 2]] C) [[3, 4, 5]] D) Error

4. What does this code output?

x = [10, 20, 30]
_, *y, _ = x
print(y)
A) [10, 30] B) [20] C) [10, 20] D) Error

5. What does this code output?

x = [i for i in range(10) if i % 3 == 0]
print(x[1:][::-1])
A) [6, 3, 0] B) [6, 3] C) [3, 0] D) [3, 6]

6. What will this code output?

x = [1, 2, 3]
y = (i for i in x)
print(list(y) == list(y))
A) True B) False C) Error D) None

7. What does this code output?

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

8. What does this code output?

x = [[j for j in range(2)] for i in range(3)]
x[0][1] = 5
print(x)
A) [[5, 1], [0, 1], [0, 1]] B) [[0, 5], [0, 1], [0, 1]] C) [[0, 1], [0, 1], [0, 1]] D) Error

9. What does this code output?

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

10. What does this code output?

x = [1, 2, 3]
print(all([i < 5 for i in x]))
A) True B) False C) Error D) None