ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(list(filter(None, [0, 1, '', 'a', None, [], [0]])))
- A. [1, 'a', None]
- B. [1, 'a', [0]]
- C. [0, 1, '', 'a', None, [], [0]]
- 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
- What is printed? python x = 5 print(x.add(3), (5).bitlength(), 5 .real)
- What is printed? python print({{'a': 1, 'b': 2}, 'a': 3})
- What is printed? python a, b, c = [1, 2, 3, 4] print(a, b, c)
- What is printed? python print(12 & -12, 12 & 11, ~12 & 0xF)
- Which loop builds a list of n items in total O(n^2) time in CPython, because each step copies the whole list?
- What is printed? python s = {1, 2, 3} s |= {3, 4} s.discard(9) print(sorted(s), 4 in s, len(s))