Reputation: 427
What I want to do is equally split a number, total
, into a list such that the list consists as many times as possible of the same number, split
, and the sum of the list will be equal to total
.
For example, given:
total = 120
split = 50
I would like to get a list as:
eqParts = [50, 50, 20] # 50 + 50 + 20 = 120 = total
Because 50
can fit two times in 120
and the remainder is 20
.
Upvotes: 1
Views: 93
Reputation: 191864
Seems like you want modulo operations and the final remainder.
Checkout divmod
>>> a = 120
>>> b = 50
>>> whole, remaining = divmod(a, b)
>>> whole*[b] + [remaining]
[50, 50, 20]
Upvotes: 3