Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_intervals(numbers):
- intervals = []
- current = [numbers[0], numbers[0]]
- for number in numbers[1:]:
- if number - current[1] != 1:
- intervals.append(current)
- current = [number, number]
- current[1] = number
- intervals.append(current)
- return intervals
- def to_str(interval):
- a, b = interval
- if b - a == 1: return "{},{}".format(a, b)
- if b - a > 1: return "{}-{}".format(a, b)
- return str(a)
- numbers = list(map(int, input().split()))
- intervals = get_intervals(numbers)
- print(*map(to_str, intervals), sep=",")
Add Comment
Please, Sign In to add comment