Parse Human Durations

easy
Unit 10 · Collections0/3 to milestone

Implement parse_duration(text) that converts strings like "1h30m", "2d 4h", "45s" or "1.5h" into a number of seconds (as a float).

Units: d (days), h, m (minutes), s. Parts may be separated by spaces, numbers may have decimals, and each unit may appear at most once. Raise ValueError for anything else (unknown units, repeated units, leftover text, empty input).

#parsing#regex2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Parse Human Durations · TechGradify