Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Use itertools to generate unique pair schedules

Create round-robin pair schedules so every participant meets every other exactly once. Handle odd participant counts with a BYE.

Python practice24 minModules & Standard LibraryAdvancedLast updated March 23, 2026

Problem statement

Given an ordered list of participant identifiers (strings), generate a round-robin schedule where each pair of participants meets exactly once across all rounds. Each round is a list of pairs (tuples of two strings). Participants should not appear more than once in a single round. If the number of participants is odd, include a 'BYE' entry so that each real participant has exactly one bye over the tournament. Requirements: - Return a list of rounds; each round is a list of 2-tuples (participant_a, participant_b). - Rounds should be generated deterministically based on the input order using the circle method (fix the first player and rotate the rest). - If the input has fewer than 2 participants, return an empty list. - Include 'BYE' as an actual partner in pairs when the participant has a bye (i.e., pairs may include the string 'BYE').

Task

Implement a deterministic round-robin scheduling function that returns rounds of unique pairs using Python's tools (including itertools).

Examples

Even number of players

Input

['A', 'B', 'C', 'D']

Output

[[('A', 'D'), ('B', 'C')], [('A', 'C'), ('D', 'B')], [('A', 'B'), ('C', 'D')]]

With 4 players there are 3 rounds. Fix 'A' and rotate the rest to produce deterministic pairings; each pair appears exactly once.

Input format

A Python list of strings representing participants, e.g. ['Alice', 'Bob', 'Carol']

Output format

A list of rounds (list), where each round is a list of 2-tuples of strings, e.g. [[('Alice','Bob'), ('Carol','Dave')], ...]

Constraints

Do not use any external libraries. The function should be deterministic and handle up to a few dozen participants efficiently. Use itertools where appropriate.

Samples

Sample 1

Input

['A', 'B', 'C']

Output

[[('A', 'BYE'), ('B', 'C')], [('A', 'C'), ('BYE', 'B')], [('A', 'B'), ('C', 'BYE')]]

Odd number of players: 'BYE' is added and appears paired with each player once across rounds.