any() with a generator expression
QuizMediumPython only
any() returns True as soon as it finds one true item. What does this print?
calls = []
def big(x):
calls.append(x)
return x > 2
print(any(big(x) for x in [1, 3, 5, 7]), calls)True [1, 3]True [1, 3, 5, 7]False [1]
This question is part of Pro+
Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.