Re: an element from a set

2010-05-17 Thread Terry Reedy
On 5/17/2010 12:53 AM, Carl Banks wrote: Even if we were to modify the set type at the C level to support it, I can't think of an easy way to get a random element without selection bias. At the C level, a (hashed) set is a list with empty slots. So the C function would have to pick random int

Re: an element from a set

2010-05-17 Thread Raymond Hettinger
On May 14, 3:24 pm, gerardob wrote: > Hello, let S be a python set which is not empty > (http://docs.python.org/library/sets.html) > > i would like to obtain one element (anyone, it doesn't matter which one) and > assign it to a variable. > > How can i do this? x = next(iter(s)) or you can suppl

Re: an element from a set

2010-05-17 Thread Bryan
Carl Banks wrote: [...] > Random element from a set is such a natural idea. > > Even if we were to modify the set type at the C level to support it, I > can't think of an easy way to get a random element without selection > bias.  For instance, if you start from a random hash code, some > elements

Re: an element from a set

2010-05-16 Thread Steven D'Aprano
On Sun, 16 May 2010 21:53:21 -0700, Carl Banks wrote: > I've never had to do it (at least not in any situations where I had any > reluctance to call list on it), but it seems like a fairly bad > limitation. Random element from a set is such a natural idea. There was a long discussion on the Pyth

Re: an element from a set

2010-05-16 Thread Carl Banks
On May 14, 11:52 pm, Chris Rebert wrote: > On Fri, May 14, 2010 at 11:23 PM, Carl Banks wrote: > > On May 14, 9:39 am, Terry Reedy wrote: > >> On 5/14/2010 11:24 AM, gerardob wrote: > >> > Hello, let S be a python set which is not empty > >> > (http://docs.python.org/library/sets.html) > > >> >

Re: an element from a set

2010-05-14 Thread Chris Rebert
On Fri, May 14, 2010 at 11:23 PM, Carl Banks wrote: > On May 14, 9:39 am, Terry Reedy wrote: >> On 5/14/2010 11:24 AM, gerardob wrote: >> > Hello, let S be a python set which is not empty >> > (http://docs.python.org/library/sets.html) >> >> > i would like to obtain one element (anyone, it doesn'

Re: an element from a set

2010-05-14 Thread James Mills
On Sat, May 15, 2010 at 4:23 PM, Carl Banks wrote: > Which brings up an interesting question: how do you get a random > element from a set? > > random.choice(list(s)) > > is the most straightforward way and will work a lot of the time, but > how would you avoid creating the list?  I can't think of

Re: an element from a set

2010-05-14 Thread Shashank Singh
On Sat, May 15, 2010 at 11:53 AM, Carl Banks wrote: > On May 14, 9:39 am, Terry Reedy wrote: > > On 5/14/2010 11:24 AM, gerardob wrote: > > > > > > > > > Hello, let S be a python set which is not empty > > > (http://docs.python.org/library/sets.html) > > > > > i would like to obtain one element (

Re: an element from a set

2010-05-14 Thread Carl Banks
On May 14, 9:39 am, Terry Reedy wrote: > On 5/14/2010 11:24 AM, gerardob wrote: > > > > > Hello, let S be a python set which is not empty > > (http://docs.python.org/library/sets.html) > > > i would like to obtain one element (anyone, it doesn't matter which one) and > > assign it to a variable. >

Re: an element from a set

2010-05-14 Thread Terry Reedy
On 5/14/2010 11:24 AM, gerardob wrote: Hello, let S be a python set which is not empty (http://docs.python.org/library/sets.html) i would like to obtain one element (anyone, it doesn't matter which one) and assign it to a variable. How can i do this? Depends on whether or not you want the el

an element from a set

2010-05-14 Thread gerardob
Hello, let S be a python set which is not empty (http://docs.python.org/library/sets.html) i would like to obtain one element (anyone, it doesn't matter which one) and assign it to a variable. How can i do this? Thanks. -- View this message in context: http://old.nabble.com/an-element