ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from collections import deque
q = deque()
for ch in 'abcd':
q.append(ch)
if len(q) > 2:
q.popleft()
print(''.join(q), q.maxlen)- A. ab None
- B. cd 2
- C. bc None
- D. cd None
Correct answer: D. cd None
This code keeps the last items by hand, and the deque has no maxlen, so maxlen is None. The last two items appended are c and d.
More Python Programming questions
- What is printed? python a = [1, 2, 3, 4, 5, 6, 7, 8] print(a[::3], a[2::-1], a[-3::2])
- What is printed? python x = [i for i in range(3)] g = (i for i in range(3)) print(x == list(g), list(g), len(x))
- What is printed? python print(sorted(['b10', 'b9', 'a100'], key=lambda s: (s[0], int(s[1:]))))
- What is printed? python print(round(3.14159, 3), round(12345, -2), round(0.5), round(1.5), round(2.5, 0))
- What is printed? python a = [3, 1, 2] b = sorted(a, reverse=True)[:2] c = sorted(a)[-2:] print(b, c, sum(b) + sum(c))
- What is printed? python word = 'Level' print(word.lower() == word.lower()[::-1], word == word[::-1], word.casefold() == 'level')