Last active
January 31, 2018 13:09
-
-
Save derlinkshaender/6ffb8a3700350889db6e5e38e7e8fa66 to your computer and use it in GitHub Desktop.
Group a list of numbers
This file contains hidden or 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
from random import shuffle | |
def partition(lst, n): | |
division = len(lst) / float(n) | |
shuffle(lst) | |
return [ lst[int(round(division * i)): int(round(division * (i + 1)))] for i in range(n) ] | |
startnumber = 1 | |
stopnumber = 24 | |
groupcount = 4 | |
print(partition(list(range(startnumber, stopnumber+1)), groupcount)) | |
# you may use https://www.pythonanywhere.com/gists/6ffb8a3700350889db6e5e38e7e8fa66/groupme.py/ipython3 | |
# to run this in a browser-based IPython notebook |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment