Valid Relay Teams Across Three Clubs
Problem
A swim relay must field exactly one swimmer from each of three clubs. A line-up is valid only if no two of the three chosen swimmers share the same id **and** no two share the same name.\n\nEach of `clubnorth`, `clubeast`, `clubwest` has columns `swimmer_id` and `swimmer_name`.\n\nReturn every valid line-up as three columns `leg_north`, `leg_east`, `leg_west` holding the swimmer names. Rows may be in any order.
Input data
Example rows — the live problem includes the full dataset.
| swimmer_id | swimmer_name |
|---|---|
| 1 | Mara |
| 2 | Niko |
| swimmer_id | swimmer_name |
|---|---|
| 3 | Otis |
| swimmer_id | swimmer_name |
|---|---|
| 3 | Otis |
| 2 | Pia |
| 10 | Mara |
Expected output
Your answer should return 2 rows with the columns leg_north, leg_east, leg_west.
Starter code (Pandas (Python))
import pandas as pd
def valid_relay_teams(clubnorth, clubeast, clubwest) -> pd.DataFrame:
# Your code here
return clubnorthSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock