Created
September 27, 2013 08:51
-
-
Save zenwerk/6725853 to your computer and use it in GitHub Desktop.
与えらた数をバランスよくN分割したリストを返す関数。
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
# -*- coding:utf-8 -*- | |
def divide(num, by): | |
""" num を バランスよく by分割する関数 | |
e,g:num=13, by=2 => [7, 6] | |
num=30, by=4 => [8, 8, 7, 7] | |
""" | |
quotient, rest = divmod(num, by) | |
ans = [quotient for i in range(by)] | |
for i in [i % len(ans) for i in range(rest)]: | |
ans[i] += 1 | |
return ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment