Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement