Last active
October 26, 2019 15:53
-
-
Save ptmcg/5def57c623c11d97912c90e6abf806c4 to your computer and use it in GitHub Desktop.
shuffled - one-line lambda to shuffle any sequence, not just shuffling lists in place
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
# shuffled.py - faster than random.shuffle, and will accept any sequence, not just indexables (like lists) | |
shuffled = lambda seq, rnd=random.random: sorted(seq, key=lambda _: rnd()) | |
print(shuffled(range(20)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment