Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Based on Lemmi solution solution in Clear category for Create Intervals by amaciel81
def create_intervals(data):
lower_bounds = [i for i in data if i - 1 not in data]
upper_bounds = [j for j in data if j + 1 not in data]
return list(zip(sorted(lower_bounds), sorted(upper_bounds)))
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, 6, 7, 8, 4, 5}) == [(1, 8)], "Second"
print('Almost done! The only thing left to do is to Check it!')
March 28, 2018