itertools comments [Was: Re: RELEASED: Python 2.3a2]
vze4rx4y at verizon.net
Thu Feb 20 23:29:06 CET 2003
> I've got one general comment on the new itertools (which I think really is
> great addition to the standard library)
> Wouldn't `xfilter`, `xmap` etc. be a better naming convention than
> `ifilter`, `imap` etc?
There were a number of possible naming styles and, in the end,
it is the module writer's perogative.
The i-prefix is supposed to be a reminder that the functions return
iterators. It has a nice, snappy feel to it and is unapologetic about
any resemblance to names used in Apple/MacIntosh marketing.
The x prefixes all predate generators and iterators. They are associated
with deprecated things like xreadlines. X is used to mark errors.
X-men are mutants. Ex-girlfriends are not positive either.
My only misgiving about the naming convention is that
islice() can be read as is-lice instead of i-slice. Oh, well.
> def xgroup(iter,n=2):
> r"""Iterate `n`-wise (default pairwise) over `iter`.
Sounds interesting enough to put on the list of ideas being
entertained. Also, it is consistent with the idea of "iterator
For the time being, my goal is to start with a small set of
tools that have proven useful in Haskell and SML. Over
time, other candidates will considered.
This one would have a much better chance if some common
use cases could be shown and if it can be demonstrated that
it is a useful building block in combination with the other
> def xwindow(iter, n=2, s=1):
> r"""Move an `n`-item (default 2) windows `s` steps (default 1) at a
> over `iter`.
I've needed this one only one time in twenty-five years of programming
(for the markov algorithm). Again, solid use cases are needed.
> A last thing, I think a `cycle` generator would be an really useful idiom
It has proved useful in the SML world.
I'm not sure it makes sense to implement it in C though.
More information about the Python-list