Skip to content

Instantly share code, notes, and snippets.

Created August 29, 2013 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6373976 to your computer and use it in GitHub Desktop.
Save anonymous/6373976 to your computer and use it in GitHub Desktop.
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