Given a list of tuples where each tuple consists of a probability and an item I\'d like to sample an item according to its probability. For example, give the list [ (.3, \'a\'),
This might do what you want:
numpy.array([.3,.4,.3]).cumsum().searchsorted(numpy.random.sample(5))