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__()))
  1. A. deabc edcba
  2. B. cdeab edcba
  3. C. deabc abcde
  4. 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

Exams that ask this topic