for x in y(): how does this work?
<p>I was looking for code to spin a cursor in the terminal and found this. I was wondering what was happening in the code. In particular <code>for c in spinning_cursor():</code> I've never seen this syntax. Is it because I am returning one element from a generator at a time with <code>yield</code>, and this is assigned to c? Any other examples of this for x in y() use?</p>

<pre><code>import sys
import time

def spinning_cursor():
    cursor='/-\|'
    i = 0
    while 1:
        yield cursor[i]
        i = (i + 1) % len(cursor)

for c in spinning_cursor():
    sys.stdout.write(c)
    sys.stdout.flush()
    time.sleep(0.1)
    sys.stdout.write('\b')
</code></pre>
