[issue1551113] random.choice(setinstance) fails

2013-05-10 Thread Raymond Hettinger
Raymond Hettinger added the comment: Sorry, this is still rejected for the reasons that Tim mentioned. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1551113 ___

[issue1551113] random.choice(setinstance) fails

2013-05-07 Thread wim glenn
wim glenn added the comment: The implementation suggested by the OP def choice(self, seq): Choose a random element from a non-empty sequence. idx = int(self.random() * len(seq)) try: result = seq[idx] # raises IndexError if seq is empty except TypeError:

[issue1551113] random.choice(setinstance) fails

2013-05-07 Thread wim glenn
wim glenn added the comment: How about if isinstance(seq, collections.Sequence): # do it the usual way .. else: return choice(list(seq)) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1551113

[issue1551113] random.choice(setinstance) fails

2009-03-26 Thread Tim Peters
Tim Peters tim.pet...@gmail.com added the comment: The CPython set/dict implementation does not guarantee minimal constant density, so quite easy doesn't apply in reality. For example, a set that once contained a million elements may still contain a million /slots/ for elements after all but

[issue1551113] random.choice(setinstance) fails

2009-03-26 Thread Tim Peters
Tim Peters tim.pet...@gmail.com added the comment: The CPython set/dict implementation does not guarantee minimal constant density, so quite easy doesn't apply in reality. For example, a set that once contained a million elements may still contain a million /slots/ for elements after all but

[issue1551113] random.choice(setinstance) fails

2009-03-26 Thread Tim Peters
Changes by Tim Peters tim.pet...@gmail.com: -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1551113 ___ ___ Python-bugs-list mailing list