I recently came across the idea of generators in Python, so I made a basic example for myself:
def gen(lim):
print 'This is a generator'
for elem in xrange(lim):
yield elem
yield 'still generator...'
print 'done'
x = gen
print x
x = x(10)
print x
print x.next()
print x.next()
I was wondering if there was any way to iterate through my variable x
and have to write out print x.next()
11 times to print everything.