ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print(list(filter(None, [0, '', [], [0], None])))
  1. A. [0, '', [], [0], None]
  2. B. [[0]]
  3. C. []
  4. D. [[0], None]

Correct answer: B. [[0]]

filter with None keeps only the truthy items. [0] is a non-empty list and so is truthy, while 0, '', [] and None are falsy.

More Python Programming questions

Exams that ask this topic