## Python 3.6 以降

```
import random
target_dict = {"a": 3, "b": 4, "c": 2}
candidates = [*target_dict]
weights = [*target_dict.values()]
x = random.choices(candidates, weights=weights)[0]
print(x)
```

## 以前

bisectを使う

```
import random
import itertools
import bisect
target_dict = {"a": 3, "b": 4, "c": 2}
candidates = [*target_dict]
weights = [*target_dict.values()]
accumulation_weights = list(itertools.accumulate(weights))
x = candidates[bisect.bisect(accumulation_weights, random.random() * accumulation_weights[-1])]
print(x)
```