Annoyingly, the following doesn't work:
from collections import Counter
import random
c = Counter([1,1,1,1,0,0])
random.choice(c) # I expect this to return 1 with probability 2/3,
# and 0 with probability 1/3.
# It actually returns 4 or 2, with probability 1/2
What is the idiomatic way to sample from a multiset in Python (any version)?
Edit yes, I do really need to use a multiset. My actual data is much bigger and just storing it in a list would not be practical.
Edit 2 I need to do this with a reasonable degree of efficiency, as my code will do this repeatedly. There will be a lot of data stored in the Counter object, and anything that involves copying all of this data into a new data structure is not going to be a viable solution.