Re: Pick items from list with probability based upon property of list member ?

2010-06-21 Thread southof40
On Jun 20, 10:58 pm, Cameron Simpson wrote: > On 20Jun2010 12:44, Stefan Behnel wrote: > | southof40, 20.06.2010 12:19: > | >I have list of of N Vehicle objects - the only possible vehicles are > | >cars, bikes, trucks. > | > > | >I want to select an object from the list with a probability of : c

Re: Pick items from list with probability based upon property of list member ?

2010-06-21 Thread southof40
On Jun 20, 11:27 pm, Mel wrote: > southof40 wrote: > > I have list of of N Vehicle objects - the only possible vehicles are > > cars, bikes, trucks. > > > I want to select an object from the list with a probability of : cars > > 0.7, bikes 0.3, trucks 0.1. > > > I've currently implemented this by

Re: Pick items from list with probability based upon property of list member ?

2010-06-21 Thread southof40
On Jun 20, 10:55 pm, Rob Williscroft wrote: > southof40 wrote in news:da3cc892-b6dd-4b37-a6e6- > b606ef967...@t26g2000prt.googlegroups.com in gmane.comp.python.general: > > > I have list of of N Vehicle objects - the only possible vehicles are > > cars, bikes, trucks. > > > I want to select an obj

Re: Pick items from list with probability based upon property of list member ?

2010-06-21 Thread southof40
On Jun 20, 10:53 pm, Steven D'Aprano wrote: > On Sun, 20 Jun 2010 03:19:55 -0700, southof40 wrote: > > I have list of of N Vehicle objects - the only possible vehicles are > > cars, bikes, trucks. > > > I want to select an object from the list with a probability of : cars > > 0.7, bikes 0.3, truck

Re: Pick items from list with probability based upon property of list member ?

2010-06-21 Thread southof40
Oh yes as several have pointed out there was a typo in my original question ... I can only blame 'toolongatscreenitis' ! -- http://mail.python.org/mailman/listinfo/python-list

Re: Pick items from list with probability based upon property of list member ?

2010-06-21 Thread southof40
Thanks to everybody ... as usual on c.l.p I'm blown away by the knowledge and skills ! I've added some replies/clarifications to other posts but thanks again to you all. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pick items from list with probability based upon property of list member ?

2010-06-20 Thread duncan smith
duncan smith wrote: southof40 wrote: I have list of of N Vehicle objects - the only possible vehicles are cars, bikes, trucks. I want to select an object from the list with a probability of : cars 0.7, bikes 0.3, trucks 0.1. I've currently implemented this by creating another list in which eac

Re: Pick items from list with probability based upon property of list member ?

2010-06-20 Thread duncan smith
southof40 wrote: I have list of of N Vehicle objects - the only possible vehicles are cars, bikes, trucks. I want to select an object from the list with a probability of : cars 0.7, bikes 0.3, trucks 0.1. I've currently implemented this by creating another list in which each car object from the

Re: Pick items from list with probability based upon property of list member ?

2010-06-20 Thread Paul Rubin
southof40 writes: > I want to select an object from the list with a probability of : cars > 0.7, bikes 0.3, trucks 0.1. You can do it with one pass through the list using a well-known online algorithm (I don't remember what it's called). Untested code: import random tprob = 0 # total prob

Re: Pick items from list with probability based upon property of list member ?

2010-06-20 Thread Steven D'Aprano
On Sun, 20 Jun 2010 11:27:30 +, Mel wrote: > southof40 wrote: > >> I have list of of N Vehicle objects - the only possible vehicles are >> cars, bikes, trucks. >> >> I want to select an object from the list with a probability of : cars >> 0.7, bikes 0.3, trucks 0.1. >> >> I've currently imple

Re: Pick items from list with probability based upon property of list member ?

2010-06-20 Thread Nobody
On Sun, 20 Jun 2010 03:19:55 -0700, southof40 wrote: > I want to select an object from the list with a probability of : cars > 0.7, bikes 0.3, trucks 0.1. > > I've currently implemented this by creating another list in which each > car object from the original list appears 7 times, each bike 3 ti

Re: Pick items from list with probability based upon property of list member ?

2010-06-20 Thread Mel
southof40 wrote: > I have list of of N Vehicle objects - the only possible vehicles are > cars, bikes, trucks. > > I want to select an object from the list with a probability of : cars > 0.7, bikes 0.3, trucks 0.1. > > I've currently implemented this by creating another list in which each > car ob

Re: Pick items from list with probability based upon property of list member ?

2010-06-20 Thread Cameron Simpson
On 20Jun2010 12:44, Stefan Behnel wrote: | southof40, 20.06.2010 12:19: | >I have list of of N Vehicle objects - the only possible vehicles are | >cars, bikes, trucks. | > | >I want to select an object from the list with a probability of : cars | >0.7, bikes 0.3, trucks 0.1. | > | >I've currently

Re: Pick items from list with probability based upon property of list member ?

2010-06-20 Thread Rob Williscroft
southof40 wrote in news:da3cc892-b6dd-4b37-a6e6- b606ef967...@t26g2000prt.googlegroups.com in gmane.comp.python.general: > I have list of of N Vehicle objects - the only possible vehicles are > cars, bikes, trucks. > > I want to select an object from the list with a probability of : cars > 0.7, b

Re: Pick items from list with probability based upon property of list member ?

2010-06-20 Thread Steven D'Aprano
On Sun, 20 Jun 2010 03:19:55 -0700, southof40 wrote: > I have list of of N Vehicle objects - the only possible vehicles are > cars, bikes, trucks. > > I want to select an object from the list with a probability of : cars > 0.7, bikes 0.3, trucks 0.1. That adds to a probability of 1.1, which is i

Re: Pick items from list with probability based upon property of list member ?

2010-06-20 Thread Stefan Behnel
southof40, 20.06.2010 12:19: I have list of of N Vehicle objects - the only possible vehicles are cars, bikes, trucks. I want to select an object from the list with a probability of : cars 0.7, bikes 0.3, trucks 0.1. I've currently implemented this by creating another list in which each car obj