Print Numbers & Ranges: The program must accept N unique integers as the input. The program must print the integers and the integer ranges present in the given N integers in sorted order separated by a comma as the output. The integer range must be represented by the starting value and the ending value separated by a hyphen.
2 <= N <= 100
0 <= Each integer value <= 10^5
The first line contains N.
The second line contains N integers separated by a space.
The first line contains the integers and the integer ranges separated by a comma.
Example Input/Output 1:
1 0 25 24 3 45 2 15 4 6
Here N = 10 and the 10 integers are 1 0 25 24 3 45 2 15 4 6.
The integers in the range 0-4 are present in the given 10 integers.
The integer 6 is present in the given 10 integers.
The integer 15 is present in the given 10 integers.
The integers in the range 24-25 are present in the given 10 integers.
The integer 45 is present in the given 10 integers.
So they are printed in ascending order as the output.
Example Input/Output 2:
1 3 4 6 5
from itertools import groupby def to_ranges(iterable): iterable = sorted(set(iterable)) for key, group in groupby(enumerate(iterable),lambda t: t - t): group = list(group) yield group, group[-1] n=int(input()) k=(list(to_ranges(list(map(int,input().split()))))) a= for i in k: if len(set(i))==1: a.append(str(i)) else: a.append('-'.join([str(j) for j in i])) print(','.join(a))