Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
to gather together solution in Creative category for Create Intervals by Lemmi
def create_intervals(data):
res = sorted(x for x in data for i in [-1, 1] if x + i not in data)
return [(x, y) for x, y in zip(res[::2], res[1::2])]
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert create_intervals({1, 2, 3, 4, 5, 7, 8, 12}) == [(1, 5), (7, 8), (12, 12)], "First"
assert create_intervals({1, 2, 3, 4, 5, 6, 7, 8}) == [(1, 8)], "Second"
print('Almost done! The only thing left to do is to Check it!')
July 27, 2017