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

Leo report at bugs.python.org
Wed Dec 16 08:52:42 CET 2009


New submission from Leo <dontsendleospam at gmail.com>:

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, require a sequence. 

The code should be changed to convert the input to a sequence instead.

Cheers,
Leo.

----------
components: Library (Lib)
messages: 96480
nosy: lleeoo
severity: normal
status: open
title: random.choice should accept a set as input
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7522>
_______________________________________


More information about the Python-bugs-list mailing list