Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{key, value(数値)}の辞書でルーレット選択
for i in self.pronlist.values():
totalweight += i
r = random.randint(1, totalweight)
for k,v in sorted(self.pronlist.items(), key=lambda x:x[1], reverse=True):
if r <= v:
pron = k
break
else:
r -= v
return pron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment