[issue7522] random.choice should accept a set as input

2012-04-30 Thread Mark Dickinson
Mark Dickinson added the comment: Michele, you might want to raise this on the python-dev or python-ideas mailing list---it'll get better exposure there than in this closed issue. For completeness, see also the previous discussion in issue 936988. -- _

[issue7522] random.choice should accept a set as input

2012-04-30 Thread Michele Mazzucchi
Michele Mazzucchi added the comment: Folks, I really think this should be addressed. Python has beautiful data structure semantics, and this is a stain in them. An implementation based on the current underlying hash table is quite simple, just pick random addresses until an active key is foun

[issue7522] random.choice should accept a set as input

2010-05-06 Thread Thomas Dybdahl Ahle
Thomas Dybdahl Ahle added the comment: I'm sorry. I see the problem then. Do you know, if there are any plans of adding a fast balanced binary search tree to pythons stdlib? -- ___ Python tracker _

[issue7522] random.choice should accept a set as input

2010-05-06 Thread Mark Dickinson
Mark Dickinson added the comment: > As far as I know, it is a binary search tree, It's not: it's based on a hash table. It's essentially a dict with keys but no values. An additional complication is that the hash table can be very sparsely filled, in the case of a large set that has had mo

[issue7522] random.choice should accept a set as input

2010-05-06 Thread Thomas Dybdahl Ahle
Thomas Dybdahl Ahle added the comment: Why not just add support to the set container? As far as I know, it is a binary search tree, so supporting random picking in O(logn) should be easy. -- nosy: +Thomas.Dybdahl.Ahle ___ Python tracker

[issue7522] random.choice should accept a set as input

2009-12-17 Thread Leo
Leo added the comment: Thanks for the suggestions "random.sample(s, 1)[0]" and "x=next(iter(s))". A counterpoint: isn't this a classic example of where polymorphism enables a more elegant, simple, and clear (dare I say Pythonic) approach? The complexity of allowing sets as inputs, even with

[issue7522] random.choice should accept a set as input

2009-12-16 Thread Raymond Hettinger
Raymond Hettinger added the comment: The underlying data structure for sets doesn't lend itself to an efficient method of random selection. It is best for the programmer to explictly convert to a sequence and then make the random selection (that way the conversion cost isn't hidden). If you d

[issue7522] random.choice should accept a set as input

2009-12-16 Thread Mark Dickinson
Mark Dickinson added the comment: This would be a new feature, so would have to wait for Python 2.7 / 3.2 (2.6 is only receiving bugfixes). -- assignee: -> rhettinger nosy: +mark.dickinson, rhettinger type: behavior -> feature request versions: +Python 2.7, Python 3.2 -Python 2.6 __

[issue7522] random.choice should accept a set as input

2009-12-15 Thread Leo
New submission from Leo : The following code should just work: import random random.choice(set(range(5))) instead the output is TypeError: TypeError: 'set' object does not support indexing The algorithm in random.choice requires a sequence, but the semantics of choice do not, and should not,