ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
print(list(map(len, ['ab', 'c', ''])), list(filter(None, [0, 1, '', 'a'])), any([]), all([]))
  1. A. [2, 1, 0] [1, 'a'] False True
  2. B. [2, 1, 0] [1, 'a'] True True
  3. C. [2, 1] [1, 'a'] False True
  4. D. [2, 1, 0] [0, 1] False True

Correct answer: A. [2, 1, 0] [1, 'a'] False True

map(len) gives the lengths, and filter(None) drops falsy values such as 0 and the empty string. any of an empty iterable is False, and all of an empty iterable is True.

More Python Programming questions

Exams that ask this topic