[Python-ideas] Allow random.choice, random.sample to work on iterators

Sjoerd Job Postmus sjoerdjob at sjoerdjob.com
Thu Dec 1 03:19:34 EST 2016


On Wed, Nov 30, 2016 at 02:32:54PM -0600, Nick Timkovich wrote:
> a generator with known length that's not indexable (a rare beast?).

Not as rare as you might think:

>>> k = set(range(10))
>>> len(k)
10
>>> k[3]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  TypeError: 'set' object does not support indexing


More information about the Python-ideas mailing list