Compress Numbers into Ranges

easy
Unit 6 · Decimal & Validation0/3 to milestone

Implement to_ranges(nums) that sorts and de-duplicates integers, then formats runs of consecutive numbers as start-end (two or more numbers) or a single number, joined by commas:

[5, 1, 2, 3, 7, 8, 10] → "1-3,5,7-8,10"

Also implement the inverse from_ranges(text) returning a sorted list of ints (an empty string gives []).

#lists#formatting2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Compress Numbers into Ranges · TechGradify