Created
August 29, 2013 03:30
-
-
Save anonymous/6373976 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
def countsort(unsorted_list): | |
counts = {} | |
for num in unsorted_list: | |
if num in counts: | |
counts[num] += 1 | |
else: | |
counts[num] = 1 | |
sorted_list = [] | |
for num in xrange(min(unsorted_list), max(unsorted_list) + 1): | |
if num in counts: | |
for j in xrange(counts[num]): | |
sorted_list.append(num) | |
return sorted_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment