[Python-3000] Builtin iterator type

George Sakkis george.sakkis at gmail.com
Tue Nov 14 23:28:36 CET 2006


On 11/14/06, Mike Klaas <mike.klaas at gmail.com> wrote:

> On 11/14/06, George Sakkis <gsakkis at rutgers.edu> wrote:
>
> > And for those objecting to touching the existing iter() or bloating
> > the builtin namespace with yet another builtin, let me mention that we
> > can get rid of *two* existing functions which for some reason were
> > promoted to builtin status, although they conceptually belong in
> > itertools: enumerate and reversed.
>
> Well, "conceptually" all itertools are not equal.  enumerate and
> reversed (and let's not forget xrange) are among my most-used
> "itertools"--enumerate in particular is used is virtually every
> module.  Some tools in itertools also belong to that category--izip in
> particular is used heavily in my code.  Some of the heavily-used
> itertools are already being pseudo-promoted to builtins: zip, map,
> (and maybe? filter) are turning into izip, imap, and ifilter.
>
> I will admit that itertools are among the few modules that are
> "first-class" import citizens in my code, that is, I tend to import
> the symbols directly:
>
> from itertools import groupby, chain

I do the same, and that's exactly my point. Iterators, generators,
generator comprehensions are among the core python features. Their
status is promoted steadily in every new version; the latest 2.5 is no
exception. Itertools is not yet another obscure module; it includes
functions that provide fundamental operations that apply on any
iterable.

> I don't see the problem of importing important language functionality.
>  Most languages since c have required somthing similar.
>
> -Mike

Most languages since C are not as readable and elegant as Python. I
think we all agree that list1[5:] + list2 is much better than the
hypothetical
    list1.getslice(5,None).concatenate(list2)
or
    from sequenceutils import concatenate, getslice
    concatenate(getslice(list1,5,None), list2)

Unfortunately, people here seem to consider natural the latter when it
comes to itertools. Oh well, whatever.

George


More information about the Python-3000 mailing list