Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Create Intervals by dx2-66
def create_intervals(data):
"""
Create a list of intervals out of set of ints.
"""
l = sorted(data)
if not l:
return []
result = []
start = l[0]
end = 0
for i in range(len(l)):
if i == len(l)-1:
result.append((start, l[i]))
elif l[i]+1 != l[i+1]:
result.append((start, l[i]))
start = l[i+1]
return result
April 19, 2022