Do you have real-world use cases for map's None fill-in feature?
Raymond Hettinger
python at rcn.com
Tue Jan 10 03:56:35 EST 2006
[Raymond Hettinger]
> > I am evaluating a request for an alternate version of itertools.izip()
> > that has a None fill-in feature like the built-in map function:
> >
> > >>> map(None, 'abc', '12345') # demonstrate map's None fill-in feature
[Paul Rubin]
> I think finding different ways to write it was an entertaining
> exercise but it's too limited in usefulness to become a standard
> feature.
Makes sense.
> I do think some idiom ought to develop to allow checking whether an
> iterator is empty, without consuming an item. Here's an idea:
> introduce something like
>
> iterator = check_empty(iterator)
There are so many varieties of iterator that it's probably not workable
to alter the iterator API for all of the them. In any case, a broad
API change like this would need its own PEP.
> There are some obvious problems with the above:
>
> 1) the new iterator should support all of the old one's attributes,
> not just inherit its operations
> 2) In the case where the old iterator is already buffered, the
> constructor should just peek at the lookahead instead of making
> a new object. That means that checking an iterator multiple times
> won't burn more and more memory.
>
> Maybe there is some way of doing the above with metaclasses but I've
> never been able to wrap my head around those.
Metaclasses are unlikely to be of help because there are so many,
unrelated kinds of iterator -- most do not inherit from a common
parent.
Raymond
More information about the Python-list
mailing list