← Back to Data Structures & Algorithms
Question 546
Take Turns In A Queue
Take Turns In A Queue
Write take_turns(names: list[str], rounds: int) -> list[str] using from collections import deque: put the names in a deque, then for each of rounds turns take the person at the front with popleft(), record them in a served list, and put them at the back with append() so the line keeps cycling. Return the served list. At least one name is always given. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: two lines, space-separated names and then the number of rounds; the tests print the served names on one line separated by spaces.
Expected Output:
ann bob cat ann bob= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Data Structures & Algorithms
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.