[pyar] Cómo obtenes N elemento de un generador?

Juanjo Conti jjconti en gmail.com
Lun Ago 23 17:33:01 ART 2010


Les dejo mi intento infructífero; cómo se hace?

>>> def a():
...     for x in range(10):
...             yield x
...
>>> a()
<generator object a at 0xb76c89b4>
>>> c = a()
>>> c[0:4]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'generator' object is unsubscriptable
>>> c.next()
0
>>> c.next()
1
>>> c.next()
2

-- 
Juanjo Conti
blog: http://www.juanjoconti.com.ar
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20100823/3fd3b2f1/attachment.html>


More information about the pyar mailing list