[pyar] Devolver 2 valores generados por función yield

Mati Barriento elmatibarriento en gmail.com
Dom Oct 5 18:26:48 ART 2014


Querida lista, tengo esta funcion que genera "longer" cantidad de cifras de
Pi
def make_pi(longer):
      i = -1
      q, r, t, k, m, x = 1, 0, 1, 1, 3, 3
      while i < longer:
         if 4 * q + r - t < m * t:
            i += 1
            yield m
            q, r, t, k, m, x = 10*q, 10*(r-m*t), t, k, (10*(3*q+r))//t -
10*m, x
         else:
            q, r, t, k, m, x = q*k, (2*q+r)*x, t*x, k+1,
(q*(7*k+2)+r*x)//(t*x), x+2

Lo que necesito es consumir 2 veces la funcion para devolver un par de 2
cifras, es decir: '14', '15' etc, y asi la cantidad que "longer" haya
definido (o longer x2)

trate de:
x = next(make_pi(longer))
y = next(make_pi(longer))
 return tuple([x,y])

pero devolvia 2 veces el mismo numero....

Uso python 3.3

GRACIAS!!
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20141005/7310df5a/attachment.html>


More information about the pyar mailing list