Advanced Collections

Preview — 3 of 10 questions

What is the output of the following code?

javascript
numbers = [1, 2, 3, 4, 5]
a, *b, c = numbers
print(a, b, c)
A[1] [2, 3, 4] [5]
B1 [2, 3, 4, 5] 5
CTypeError: too many values to unpack
D1 [2, 3, 4] 5

What is the output of the following code?

javascript
grid = [[0] * 3] * 3
grid[0][0] = 1
print(grid)
A[[1, 0, 0], [0, 0, 0], [0, 0, 0]]
B[[1, 0, 0], [1, 0, 0], [1, 0, 0]]
C[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
DTypeError

What is the output of the following code?

javascript
d = {"a": 1, "b": 2}
keys_view = d.keys()
d["c"] = 3

print(list(keys_view))
print(len(keys_view))
ARuntimeError: dictionary changed size during iteration
B['a', 'b'] then 2
C['a', 'b', 'c'] then 3
D['a', 'b', 'c'] then 2

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.