[omaha] Iterators vs Generator!!

Wes Turner wes.turner at gmail.com
Tue Oct 28 01:07:39 CET 2014


Both iterators and generators can be functionally composed.

Generators can maintain local state as they are iterated through.

Learning not to consume iterators and generators is a good thing; both for
Python 3 (where things like .keys() are now .iterkeys()) and for asyncio
("yield from").

An object can implement .__iter__() /.next()) and not .__len__().

Docs:

https://docs.python.org/2/reference/datamodel.html#the-standard-type-hierarchy

https://docs.python.org/2/glossary.html#term-generator

https://docs.python.org/2/glossary.html#term-iterator

https://docs.python.org/2/tutorial/classes.html#generators

https://docs.python.org/2/howto/functional.html#iterators

https://docs.python.org/2/tutorial/classes.html#iterators

https://docs.python.org/2/library/itertools.html

https://scipy-lectures.github.io/advanced/advanced_python/index.html#iterators-generator-expressions-and-generators

https://docs.python.org/3/library/asyncio.html (3.4+)

Tools for working functionally with iterators and generators:

https://github.com/pytoolz/toolz

https://github.com/kachayev/fn.py/blob/master/README.rst

http://funcy.readthedocs.org/en/latest/
On Oct 27, 2014 4:02 PM, "Varun Mehta" <varun.sagi20 at gmail.com> wrote:

> Hi all
>
> I have a query regarding the Iterator vs Generator.
> Generator is specific type of Iterator.
> But both still use next function to produce next value and save memory.
>
> So, which should be preferred?
> Any advantage of one over other?
>
> Warm Regards
> Varun Mehta
>
>
>
> _______________________________________________
> Omaha Python Users Group mailing list
> Omaha at python.org
> https://mail.python.org/mailman/listinfo/omaha
> http://www.OmahaPython.org
>


More information about the Omaha mailing list