ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from collections import deque d = deque([1, 2, 3]) d.extendleft([4, 5]) print(list(d))
- A. [3, 2, 1, 4, 5]
- B. [5, 4, 1, 2, 3]
- C. [4, 5, 1, 2, 3]
- D. [1, 2, 3, 4, 5]
Correct answer: B. [5, 4, 1, 2, 3]
extendleft adds each item to the left end in turn, so 4 goes in front of 1 and then 5 goes in front of 4. The items arrive in reversed order.
More Python Programming questions
- What is printed? python x = 'abc' print(x.replace('', '-'))
- What is printed? python try: 'abc'.split('') except ValueError as e: print(e)
- What is printed? python a = [1, 2, 3] for x in a: a.remove(x) print(a)
- What is printed? python print(10 -2, 10 2.0, 10 // 3.0)
- What is printed? python print(all([]), any([]), all(x > 0 for x in [1, 0]))
- What is printed? python print(list(map(lambda x, y: x y, [1, 2, 3], [4, 5])))