python generate a infinite list with certain condition
<p>I know there is generator yield in python like:</p>

<pre><code>def f(n): 
    x = n
    while True:
        yield x
        x = x+1
</code></pre>

<p>So I try to convert this haskell function into python without using iterate: <a href="http://stackoverflow.com/questions/39809592/haskell-infinite-recursion-in-list-comprehension">Haskell infinite recursion in list comprehension</a></p>

<p>I'm not sure how to define base case in python, also not sure how to combine if statement with this yield staff! here is what I try to do:</p>

<pre><code>def orbit(x,y):
    while True:
        yield p (u,v)
        p (u,v) = (u^2 - v^2 + x, 2 * u * v + y)
</code></pre>

<p>I dont see where you're getting the <code>p</code> from. As far as I can see you can almost literally translate it from Haskell:</p>

<pre><code>def orbit(x, y):
    u, v = 0, 0
    while True:
        u, v = u**2 â v**2 + x, 2*u*v + y
        yield u, v
</code></pre>

<p>In their example, calling the function as <code>orbit(1, 2)</code>, <code>u</code> will be bound to <code>1</code> and <code>v</code> to <code>2</code> in the first round, then that (<code>(1, 2)</code>) is yielded. In the next iteration, <code>u = 1**2 - 2**2 + 1 = 1 - 4 + 1 = -2</code> and <code>v = 2*1*2 + 2 = 6</code>.</p>

python list python-3.x yield