Skip to content

Instantly share code, notes, and snippets.

@erikzaadi
Created September 16, 2013 10:42
Show Gist options
  • Save erikzaadi/6579100 to your computer and use it in GitHub Desktop.
Save erikzaadi/6579100 to your computer and use it in GitHub Desktop.
unsorted = {1, 59, 12, 43, 4, 58, 5, 13, 46, 3, 6}
sorted_list = sorted(unsorted)
list_length = len(sorted_list)
if list_length < 2:
print sorted_list
current = [sorted_list[0]]
for index in xrange(1, list_length):
if sorted_list[index - 1] + 1 == sorted_list[index]:
current += [sorted_list[index]]
else:
print current, ',',
current = [sorted_list[index]]
if index + 1 == list_length:
print current
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment