EasyPython
Tuples — Pack, Unpack and Swap
PythonTuplesData Types
Implement solve(pairs) that receives a list of 2-element tuples (a, b) and returns a new list where each tuple has its elements swapped: (b, a).
Also implement solve_stats(numbers) that returns a tuple (minimum, maximum, total) for a list of numbers.
Since Judge0 uses a single entry point, implement solve(data, mode):
- If
mode == "swap":datais a list of 2-tuples → return list of swapped tuples. - If
mode == "stats":datais a list of numbers → return(min, max, sum).
Examples
solve([(1, 2), (3, 4)], "swap")→[(2, 1), (4, 3)]solve([3, 1, 4, 1, 5], "stats")→(1, 5, 14)
Sample tests
Test #1Swap pairs
Input: [[[1,2],[3,4]],"swap"]
Output: [[2,1],[4,3]]
Test #2Stats basic
Input: [[3,1,4,1,5],"stats"]
Output: [1,5,14]
Test #3Empty swap
Input: [[],"swap"]
Output: []