Loading exercise...

Exercise: Cycle Through a Turn Order

Avatar image for Rafael Cangussu

Rafael Cangussu on Aug. 19, 2026

from collections import deque

def take_turns(players, turns):
    """Return a deque of players after `turns` turns."""
    d = deque(players)
    d.rotate(-turns)
    return d
Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on Aug. 20, 2026

@Rafael Cangussu that works, and it passes every test in the exercise, including both bonus ones. I ran it to check:

>>> take_turns(["John", "Paul", "George", "Richard", "Pete"], 3)
deque(['Richard', 'Pete', 'John', 'Paul', 'George'])
>>> take_turns([], 3)
deque([])

The test that checks you’re using the deque’s end operations accepts .rotate() right alongside .popleft(), so you’re in the clear there too.

The exercise steers toward .popleft() and .append() mostly because .rotate() doesn’t turn up until Exploring Other Features of Deque later in the course, so looks like you got there early. The solution notes point to your version as the alternative worth knowing.

One thing .rotate() hands you for free: it reduces the rotation modulo the length before it moves anything, so an absurd number of turns costs the same as a small one.

>>> take_turns(["John", "Paul", "George", "Richard", "Pete"], 10_000_000)
deque(['John', 'Paul', 'George', 'Richard', 'Pete'])

The .popleft() and .append() loop would grind through ten million iterations to land in the same spot :)

Become a Member to join the conversation.