Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
zip, sorted, [-1, 1] One-liner solution in Creative category for Create Intervals by Lemmi
def create_intervals(data):
return list(zip(*[sorted(x for x in data if x + i not in data) for i in [-1, 1]]))
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
Comments: