Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
My clear solution solution in Clear category for Create Intervals by Marcin_Ramotowski
def create_intervals(data):
"""
Create a list of intervals out of set of ints.
"""
data = list(data)
data.sort()
if len(data) < 1:
return data
begins = [data[0]]
ends = []
for i in range(1,len(data)):
if data[i] - data[i-1] > 1:
ends.append(data[i-1])
begins.append(data[i])
ends.append(data[-1])
return list(zip(begins,ends))
July 16, 2021