Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
iterints solution in Speedy category for Create Intervals by PythonWithPI
def create_intervals(data):
"""
Create a list of intervals out of set of ints.
"""
if not data:
return []
ints = list(data)
ints.sort()
iterints = iter(ints)
intervals = []
intervals.append([next(iterints)] * 2)
for integer in iterints:
if intervals[-1][-1] == integer - 1:
intervals[-1][-1] = integer
else:
intervals.append([integer, integer])
return list(map(tuple, intervals))
Nov. 6, 2019
Comments: