AppliedMultiple choice
What does [f() for f in [lambda: i for i in range(3)]] evaluate to?
- A
[0, 1, 2], one value captured by each lambda when it was created - B
[2, 2, 2] - CA
NameError, becauseiis out of scope when the lambdas run - D
[None, None, None], since lambdas without a return statement return nothing
The worked solution is in Premium
The answer, the full working and the one idea to take away – for this and all 1,322 questions in the bank. Answer it in practice and your working is marked, with a known mistake named when you make one.
Learn the method
Reported in interviews at
More python and data for quants questions
- What happens with def f(x, acc=[]): acc.append(x); return acc?Foundation
- What is sum([i * j for i in range(3) for j in range(3) if i != j])?Foundation
- What does -7 // 2 evaluate to in Python?Foundation
- After g = (x for x in range(3)) and list(g), what is len(list(g))?Foundation
- When should you compare with is rather than == in Python?Foundation
- Roughly how much memory does a list of ten million distinct Python integers…Applied