Skip to content

10. Safe Min and Max

Difficulty: Easy · Topic: Core Python & data structures

Write fare_range(fares): return a tuple (lowest, highest) of the fares, ignoring missing values (None).

Example: fare_range([120, None, 80, 200]) gives (80, 200).

Your code runs in CPython on our servers against 6 tests, including hidden ones.

Sample test

fare_range([120, None, 80, 200])

Expected: (80, 200)

Hints

Hint 1min and max accept default=: what to return for an empty input instead of raising ValueError.
Hint 2Filter with is not None, not with plain truthiness: 0 is false.
Hint 3A generator is used up after one pass. Collect the values into a list once, then take both min and max.

Learn the concepts

More Python problems

All Python problems