Skip to content

Instantly share code, notes, and snippets.

@tmehlinger
Last active August 29, 2015 14:22
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 tmehlinger/9f6489ab50cce5e530ac to your computer and use it in GitHub Desktop.
Save tmehlinger/9f6489ab50cce5e530ac to your computer and use it in GitHub Desktop.
#yolo sort
#!/usr/bin/env python3.4
from itertools import tee
from random import randint, shuffle
import sys
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
return zip(a, b)
def is_sorted(seq):
for a, b in pairwise(seq):
if a > b:
return False
return True
if __name__ == '__main__':
s = [randint(0, 100) for _ in range(int(sys.argv[1]))]
print('sequence is', s)
shuffle(s)
print('"sorted" is', s)
msg = '#yolo'
if is_sorted(s):
msg = '#swag'
print(msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment