Skip to content

Instantly share code, notes, and snippets.

@ptmcg
Last active October 26, 2019 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptmcg/5def57c623c11d97912c90e6abf806c4 to your computer and use it in GitHub Desktop.
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
# 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