Skip to content

Instantly share code, notes, and snippets.

@aloisdg
Created March 9, 2021 10:56
Show Gist options
  • Save aloisdg/97615eba3c62cb09697ae7890a0cfdc4 to your computer and use it in GitHub Desktop.
Save aloisdg/97615eba3c62cb09697ae7890a0cfdc4 to your computer and use it in GitHub Desktop.
import random
def transpose(groups):
# return list(map(list, zip(*groups)))
result = []
longest = max([len(x) for x in groups])
for index in range(longest):
sub = []
for group in groups:
if index < len(group):
sub.append(group[index])
result.append(sub)
return result
def shuffleEach(groups):
result = []
for group in groups:
result.append(random.sample(group, len(group)))
return random.sample(result, len(result))
groups = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15]]
print(transpose(shuffleEach(groups)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment