Created
September 16, 2013 10:42
-
-
Save erikzaadi/6579100 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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