On Sep 21, 2009, at 9:52 AM, Kent Johnson wrote:
Calling a generator function gives you something that can be iterated.
You can create a list out of it (by passing it to the list() function)
or you can iterate the items in it directly with a for loop. Using the
example above, you could say
for item in roundrobin('abc', [], range(4), (True,False)):
print item
I kinda understand conceptually what iterators and generators do
and why
they are "a honking good idea" (why create 100 of x when we just
want the
100th, etc.) what i don't get is the syntax and how they are used
in real
life. How generator and iterators behave in the wild.
It's really not that bad. They are just a generalization of what you
have already been doing with lists.
Even the Lutz is too
terse and generally poor on these two complex and relatively new
constructs.
They are a dark and obscure magic.
No, really they are not difficult. Read my essay and ask questions if
you don't understand.
Thanks. I have some time today and will read up on what you sent me
and revisit
the lutz and other docs. It appears it is not so impenetrable as i
initially though. Well iterators
aren't maybe, but generator do look tricky. So interators iterate over
lists, tuples, strings, dictionaries
and any data type that is iterable, and generators are ways to make
new iterables? Anyway, i will
brew some coffee and hit those links. Thanks,
-kevin
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor