Skip to content

Instantly share code, notes, and snippets.

@brunobord
Created December 1, 2014 10:53
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 brunobord/c7485443733b129ef3d2 to your computer and use it in GitHub Desktop.
Save brunobord/c7485443733b129ef3d2 to your computer and use it in GitHub Desktop.
Stupid Sort
import random
# inspired by: http://40.media.tumblr.com/796b89338891a81dd82bf0d9fc4d4c93/tumblr_nfrqzkKahq1t8e84jo1_500.png
def stupid_sort(s):
_initial_type = type(s)
if isinstance(s, (str, unicode)):
s = list(s)
while True:
pivot = s[0]
good = True
for item in s[1:]:
if item < pivot:
good = False
break
pivot = item
if good:
if _initial_type in (str, unicode):
return ''.join(s)
return s
random.shuffle(s)
if __name__ == '__main__':
print stupid_sort('typewriter')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment