ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(list(filter(lambda s: s.startswith('a'), ['ab', 'ba', 'ac'])), ' a b '.strip().split(' '))
  1. A. ['ab', 'ba', 'ac'] ['a', 'b']
  2. B. ['ab', 'ac'] ['a', 'b']
  3. C. ['ab', 'ac'] ['a', 'b', 'c']
  4. D. ['ab'] ['a', 'b']

Correct answer: B. ['ab', 'ac'] ['a', 'b']

filter keeps the strings starting with a. strip removes the outer spaces first, then split with a single space gives a and b with no empty pieces.

More Python Programming questions

Exams that ask this topic