Skip to content

Instantly share code, notes, and snippets.

@tmehlinger
Last active Aug 29, 2015
Embed
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)
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