'Find different elements individual or series in a list of non duplicate random numbers

I have a list of numbers, for example: [4,5,6,8,229,230,250,170,118,119,120].

I'm trying to make a function that would give:

results = [4 to 6, 8, 118 to 120, 170, 229 to 230, 250]

Thank you for the help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source