Skip to content

Instantly share code, notes, and snippets.

@aaronhanson
Last active August 29, 2015 14:07
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 aaronhanson/5a2a234c2383919629de to your computer and use it in GitHub Desktop.
Save aaronhanson/5a2a234c2383919629de to your computer and use it in GitHub Desktop.
Seeded Groups
def seeded_groups(lst, n):
l = list(lst)
# create empty groups
groups = [[] for i in range(n)]
# prefill the groups with placeholders
for idx, elem in enumerate(l):
mod_idx = idx % n
groups[mod_idx].append(0)
# replace placeholders
for group in groups:
for idx, elem in enumerate(group):
group[idx] = l.pop(0)
return groups
print("Seeded\n%r" % seeded_groups(range(1, 11), 3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment