List Quiz: 10
Advanced Python Lists Quiz
Answer the following highly challenging Python list questions:
Time Remaining: 20:00
1. What will this code output?
x = [i**2 for i in range(1, 10, 2)]
print(x[3])
A) 25
B) 49
C) 9
D) Error
2. What is the output of this code?
x = [sum([j for j in range(i)]) for i in range(5)]
print(x)
A) [0, 1, 3, 6, 10]
B) [0, 1, 3, 6]
C) [1, 2, 3, 4]
D) Error
3. What does this code output?
x = [[i * j for i in range(3)] for j in range(3)]
print(x[2][1])
A) 0
B) 2
C) 4
D) Error
4. What will this code output?
x = [1, 2, 3]
y = [(lambda a: a + i)(i) for i in x]
print(y)
A) [2, 4, 6]
B) [1, 3, 5]
C) [2, 3, 4]
D) Error
5. What does this code output?
x = [i for i in range(5)]
y = [a * b for a, b in zip(x, x[::-1])]
print(max(y))
A) 4
B) 6
C) 8
D) 10
6. What will this code output?
x = [1, 2, 3, 4]
y = x[::-2]
z = [i ** 2 for i in y]
print(z)
A) [16, 4]
B) [4, 16]
C) [1, 9]
D) Error
7. What does this code output?
x = [1, 3, 6]
y = [i**0.5 for i in x if i % 3 == 0]
print(sum(y))
A) 2.0
B) 2.449
C) 2.645
D) Error
8. What will this code output?
x = ["apple", "banana", "cherry"]
y = "".join([fruit[-2] for fruit in x])
print(y)
A) eae
B) rna
C) aan
D) Error
9. What does this code output?
x = [2, 4, 6, 8]
y = [[i, i**2] for i in x]
print(y[1][1])
A) 4
B) 8
C) 16
D) Error
10. What will this code output?
x = [10, 20, 30]
y = x[:]
y[1] = 99
print(x, y)
A) [10, 99, 30], [10, 99, 30]
B) [10, 20, 30], [10, 20, 30]
C) [10, 20, 30], [10, 99, 30]
D) Error