List Quiz: 07

Python Lists Quiz - Master Level

Python Lists Quiz - Master Level

Answer the following master-level questions about Python lists:

Time Remaining: 10:00

1. What does this code output?

x = [i for i in range(10) if i % 3 == 1]
y = [i * j for i in x for j in range(3) if j > i % 2]
print(y)
A) [1, 2, 4, 6, 10, 12] B) [1, 4, 6, 10, 12, 16] C) [1, 2, 3, 4, 6] D) [2, 4, 8, 10]

2. What does this code output?

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

3. What will this code output?

x = [1, 2, 3, 4]
y = [i + j for i, j in zip(x, x[::-1])]
print(y)
A) [5, 5, 5, 5] B) [4, 4, 4, 4] C) [5, 5, 5] D) [2, 4, 6, 8]