Sampling a population

Terry Reedy tjreedy at udel.edu
Fri Jun 2 15:22:00 EDT 2006


"Paddy" <paddy3118 at netscape.net> wrote in message 
news:1149275394.499808.31460 at i39g2000cwa.googlegroups.com...
> Brian Quinlan wrote:
>> This is less a Python question and more a optimization/probability
>> question. Imaging that you have a list of objects and there frequency in
>> a population e.g.
>>
>> lst = [(a, 0.01), (b, 0.05), (c, 0.50), (d, 0.30), (e, 0.04), (f, 0.10)]
>>
>> and you want to drawn n items from that list (duplicates allowed), with
>> that probability distribution.

For a set of probabilities that uneven, you *might* do better to sort high 
to low and do a linear search.  Or check the two common cases and then do a 
binary search on the rest.

tjr






More information about the Python-list mailing list