Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Intervals enlargment (sorted, and tupled) solution in Clear category for Create Intervals by ermichin158
def create_intervals(data):
intervals = []
for value in sorted(data):
# If there are no intervals(empty list)
# or value can not be added to last interval
# (because it will not include previous value(-s))
if not intervals or intervals[-1][1] != value - 1:
# Create new interval so interval[0] <= value <= interval[1]
# and includes all value(only 1 - value)
# So we should create interval with only 1 value
intervals.append([value, value])
else:
# Value can be part of extended interval
# so we should enlarge it to hold new value
intervals[-1][1] += 1
return [tuple(x) for x in intervals]
July 31, 2017