(Python) algorithm to randomly select a key based on proportionality/weight

前端 未结 6 1831
盖世英雄少女心
盖世英雄少女心 2020-12-09 06:33

I\'m a bit at a loss as to how to find a clean algorithm for doing the following:

Suppose I have a dict k:

>>> k = {\'A\': 68, \'B\': 62, \'         


        
6条回答
  •  自闭症患者
    2020-12-09 07:12

    one should also look at this link

    make two list for k, say xk and yk

    from scipy import stats
    custm = stats.rv_discrete(name='test', values=(xk, yk))
    custm.rvs(size=1)
    

提交回复
热议问题