Skip to content

Instantly share code, notes, and snippets.

@juanarrivillaga
Last active March 9, 2017 23:30
Show Gist options
  • Save juanarrivillaga/f67e5fc9b601bfadba79f0d25887b3c3 to your computer and use it in GitHub Desktop.
Save juanarrivillaga/f67e5fc9b601bfadba79f0d25887b3c3 to your computer and use it in GitHub Desktop.
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