Last active
March 9, 2017 23:30
-
-
Save juanarrivillaga/f67e5fc9b601bfadba79f0d25887b3c3 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
def random_items(lst): | |
lst = lst[:] # copy so original list is not mutated | |
while True: | |
random.shuffle(lst) | |
yield from lst | |
# Python 2 can't use `yield from` | |
def random_items_py2(lst): | |
lst = lst[:] | |
while True: | |
random.shuffle(lst) | |
for i in lst: | |
yield i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment