ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from collections import deque
d = deque('abcde')
d.rotate(2)
print(''.join(d), ''.join(deque('abcde').__reversed__()))- A. deabc edcba
- B. cdeab edcba
- C. deabc abcde
- D. abcde edcba
Correct answer: A. deabc edcba
rotate(2) moves the last two items to the front, giving d e a b c. Reversed iteration of a deque gives e d c b a, which is written as the string 'edcba'.
More Python Programming questions
- 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]…
- What is printed? python import heapq print(heapq.heappop([]) if False else 'ok', heapq.nlargest(1, []))
- What is the time complexity of building a heap from n items with heapq.heapify, compared with pushing the n items one by one with…
- What is printed? python x = 255 print(x.bitlength(), bin(x).count('1'), (x & -x), (x - 1) & x)