Distribute an integer amount by a set of slots as evenly as possible

前端 未结 5 501
逝去的感伤
逝去的感伤 2021-02-02 09:47

I am trying to figure an elegant way of implementing the distribution of an amount into a given set of slots in python.

For example:

7 oranges distributed onto 4

5条回答
  •  粉色の甜心
    2021-02-02 09:47

    Not sure how this works. But it returns the exact same results

    a = 23
    b = 17
    s = pd.Series(pd.cut(mylist, b), index=mylist)
    s.groupby(s).size().values
    

提交回复
热议问题