Skip to content

Instantly share code, notes, and snippets.

@daylanKifky
Created April 13, 2017 10:09
Show Gist options
  • Save daylanKifky/9e6c058258541a2987f1867c967b5334 to your computer and use it in GitHub Desktop.
Save daylanKifky/9e6c058258541a2987f1867c967b5334 to your computer and use it in GitHub Desktop.
distribute list shuffle python
a = [a for a in range(20)]
from random import shuffle
shuffle(a)
print a
#[13, 2, 4, 5, 10, 3, 0, 9, 14, 12, 8, 11, 7, 6, 15, 16, 17, 18, 1, 19]
lista = [[],[],[]]
for i,val in enumerate(a):
lista[i%3].append(val)
print lista
#[[13, 5, 0, 12, 7, 16, 1], [2, 10, 9, 8, 6, 17, 19], [4, 3, 14, 11, 15, 18]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment