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
___
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:
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
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
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
Changes by Tim Peters tim.pet...@gmail.com:
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1551113
___
___
Python-bugs-list mailing list