Last active
August 29, 2015 14:07
-
-
Save aaronhanson/5a2a234c2383919629de to your computer and use it in GitHub Desktop.
Seeded Groups
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 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