[Python-3000] map() Returns Iterator
Steven Bethard
steven.bethard at gmail.com
Mon Aug 6 17:22:58 CEST 2007
On 8/6/07, Nicko van Someren <nicko at nicko.org> wrote:
> On 4 Aug 2007, at 06:11, Kurt B. Kaiser wrote:
> > There are a number of instances where map() is called for its side
> > effect, e.g.
> >
> > map(print, line_sequence)
> >
> > with the return result ignored. In py3k this has caused many silent
> > failures. We've been weeding these out, and there are only a couple
> > left, but there are no doubt many more in 3rd party code.
>
> I'm sure that there are lots of these. Other scenarios which will
> make for ugly bugs include things like map(db_commit,
> changed_record_list).
I'd just like to say that I'll be glad to see these kind of things go
away. This is really a confusing abuse of map() for a reader of the
code.
> Filter returning an iterator is going to break lots of code which
> says things like:
> interesting_things = filter(predicate, things)
> ...
> if foo in interesting_things: ...
Actually, as written, that code will work just fine::
>>> from itertools import ifilter as filter
>>> interesting_things = filter(str.isalnum, 'a 1 . a1 a1.'.split())
>>> if 'a1' in interesting_things:
... print 'it worked!'
...
it worked!
Perhaps you meant to have multiple if clauses?
STeVe
--
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
--- Bucky Katt, Get Fuzzy
More information about the Python-3000
mailing list