List Quiz: 09
Challenging Python Lists Quiz
Answer the following complex questions about Python lists:
Time Remaining: 20:00
1. What will this code output?
x = [1, 2, 3, 4, 5]
print(x[::-2])
A) [5, 3, 1]
B) [5, 3]
C) [1, 3, 5]
D) Error
2. What is the output of this code?
x = [[i for i in range(3)] for j in range(3)]
print(x[2][0] + x[1][1])
A) 2
B) 3
C) 4
D) Error
3. What does this code output?
x = [1, 2, 3, 4]
y = [a * b for a, b in zip(x, x[::-1])]
print(y[1])
A) 2
B) 6
C) 8
D) 12
4. What will this code output?
x = [1, 2, 3]
y = [i**2 for i in x if i % 2 == 1]
print(y)
A) [1, 4, 9]
B) [1, 9]
C) [1]
D) Error
5. What does this code output?
x = [5, 10, 15]
y = [i / 5 for i in x]
print(sum(y))
A) 6.0
B) 5.0
C) 3.0
D) 4.0
6. What will this code output?
x = [[i, i**2] for i in range(3)]
print(x[1][1])
A) 1
B) 2
C) 4
D) Error
7. What does this code output?
x = [i for i in range(10) if i % 3 == 0]
print(x[::-2])
A) [9, 6, 3, 0]
B) [9, 3]
C) [9, 6, 3]
D) [0, 3, 6, 9]
8. What will this code output?
x = ["apple", "banana", "cherry"]
y = [fruit[1] for fruit in x]
print("".join(y))
A) abc
B) pbc
C) aca
D) Error
9. What does this code output?
x = [1, 2, 3, 4, 5]
y = [lambda a: a * n for n in x]
print(y )
A) 5
B) 10
C) 15
D) Error
10. What will this code output?
x = [1, 2, 3]
y = [x[i] for i in range(len(x))]
y[1] = 5
print(x, y)
A) [1, 2, 3], [1, 5, 3]
B) [1, 5, 3], [1, 5, 3]
C) [1, 2, 3], [1, 2, 3]
D) Error