Skip to content

Instantly share code, notes, and snippets.

@yyl
Created August 23, 2012 02:29
Show Gist options
  • Save yyl/3431519 to your computer and use it in GitHub Desktop.
Save yyl/3431519 to your computer and use it in GitHub Desktop.
iterates
a = [1,2,3]
i = iter(a)
i.next()
# iterator
for i in [1,2,3]:
print i*i
# generator
def square(li):
for i in xrange(1, li):
yield i*i
for i in square(3):
print i
'''
actually this is not a good example because code for generator
is much more than that of iterator.
but ...
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment