Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#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)
print('"sorted" is', s)
msg = '#yolo'
if is_sorted(s):
msg = '#swag'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment