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(' '))- A. ['ab', 'ba', 'ac'] ['a', 'b']
- B. ['ab', 'ac'] ['a', 'b']
- C. ['ab', 'ac'] ['a', 'b', 'c']
- 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
- What is the time complexity of x in d where d is a collections.deque of n items?
- What is printed? python x = 10 print(x.bitlength(), (x >> 1).bitlength(), (x << 3) // 16)
- What is printed? python words = ['tea', 'eat', 'tan', 'ate', 'nat'] groups = {} for w in words: groups.setdefault(''.join(sorted(w))…
- What is printed? python print(0.2 + 0.4 + 0.1 == 0.7, 0.1 + (0.2 + 0.4) == 0.7, 0.2 + 0.1 + 0.4 == 0.7)
- What is printed? python print(sorted([(1, 'b'), (1, 'a'), (0, 'z')], reverse=True)[0])
- What is printed? python print(list(map(len, ['', 'ab', 'abc'])), sum(map(len, ['', 'ab', 'abc'])))