Created
March 5, 2018 21:42
-
-
Save luther9/b11dd370b4427489255641601a580c8a to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
# John's version. | |
def shuffle(deck): | |
return [e for l in [a for a in zip(deck[:(len(deck)//2)], deck[(len(deck)//2):])] for e in l] | |
# Slightly simplified. Above, the inner comprehension has just "a for a" with no | |
# "if" at the end, so we can reduce it down to just the iterator. | |
def shuffle1(deck): | |
half = len(deck) // 2 | |
return [e for l in zip(deck[:half], deck[half:]) for e in l] | |
deck = range(52) | |
shuffled = shuffle1(deck) | |
print(shuffled) | |
assert shuffle(deck) == shuffled |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment