ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from collections import deque d = deque([1, 2, 3, 4, 5], maxlen=3) d.append(6) d.appendleft(0) print(list(d))
- A. [0, 5, 6]
- B. [0, 4, 5]
- C. [0, 1, 2]
- D. [4, 5, 6]
Correct answer: B. [0, 4, 5]
A maxlen deque keeps only the newest items: creation keeps [3, 4, 5], append(6) drops the leftmost item to give [4, 5, 6], and appendleft(0) drops the rightmost item 6, leaving [0, 4, 5].
More Python Programming questions
- What is printed? python x = [0] 3 y = [[0] 2] 2 y[0][1] = 7 print(x, y)
- What is printed? python import bisect vals = [10, 20, 30] print(bisect.bisectleft(vals, 0), bisect.bisectleft(vals, 35)…
- What is printed? python from collections import deque d = deque('abcde') d.rotate(2) print(''.join(d), ''.join(deque('abcde').reversed()))
- What is printed? python print(int('0' 5 + '7') + int(' -3 '), len(str(int('9' 50) + 1)))
- What is printed? python import math print(math.isqrt(99), math.isqrt(100), round(2.5), round(3.5))
- What is printed? python import itertools print(list(itertools.accumulate([3, 1, 4, 1, 5], max))[-1], list(itertools.accumulate([3, 1, 4]…