Created
December 1, 2014 10:53
-
-
Save brunobord/c7485443733b129ef3d2 to your computer and use it in GitHub Desktop.
Stupid Sort
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
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