Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Create Intervals by zgub4
def create_intervals(data):
if not data:
return list()
final_list = list()
s = sorted(data)
current_min = s[0]
for i in range(0, len(s) - 1):
if s[i+1] - s[i] > 1:
final_list.append((current_min, s[i]))
current_min = s[i+1]
final_list.append((current_min, s[-1]))
return final_list
if __name__ == '__main__':
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!')
Oct. 22, 2017