a few extensions for the itertools

Carl Banks pavlovevidence at gmail.com
Sun Nov 19 19:23:08 EST 2006


Paul McGuire wrote:
> "Mathias Panzenboeck" <e0427417 at student.tuwien.ac.at> wrote in message
> news:4560bfb0$0$10578$3b214f66 at tunews.univie.ac.at...
> >I wrote a few functions which IMHO are missing in python(s itertools).
> >
> > You can download them here:
> > http://sourceforge.net/project/showfiles.php?group_id=165721&package_id=212104
> >
> > A short description to all the functions:
> >
> Just a couple of questions:
>
> > iproduct(iterable, start=0) -> value
> > Returns the product of the elements of a iterable
> > times the value of parameter 'start'.  When the
> > iterable is empty, returns start.
> >
> Wouldn't 1 be a better default value for start?

I concur; start should default to 1.


> > forall(predicate, iterable, default=True) -> bool
> > Returns True, when for all elements x in iterable
> > predicate(x) is True. When the iterable is empty,
> > returns default.
> >
> > forany(predicate, iterable, default=False) -> bool
> > Returns True, when for any element x in iterable
> > predicate(x) is True. When the iterable is empty,
> > returns default.
> >
> How are these different from all and any in Python 2.5?

1. These functions apply a predicate to the items.  It's simple enough
to do with any/all and a genexp, but by the same argument, it's simple
enough to do imap and ifilter with a plain genexp.
2. They have default values.  Default values for any and all don't make
sense, and I don't think they make sense here, either.  All of nothing
is always True; any of nothing is always False.


Carl Banks




More information about the Python-list mailing list