ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: B. [1, 'a', [0]]

filter with None keeps the items that are truthy. 0, the empty string, None and the empty list are falsy. The one-element list [0] is truthy because it is not empty.

More Python Programming questions

Exams that ask this topic