Iterating over a function call

Vlastimil Brom vlastimil.brom at gmail.com
Mon Feb 1 17:39:09 EST 2010


2010/2/1 Gerald Britton <gerald.britton at gmail.com>:
> Hi -- I have many sections of code like this:
>
>    for value in value_iterator:
>         value_function(value)
>
> I noticed that this does two things I don't like:
>...
> --
> Gerald Britton
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Hi,
just to add to the collection of possible approaches (personally, I
find the straightforward versions fine, given the task ... )
If you know, that the called function (used for side effect in any
case) doesn't return any "true" value, you could use
any(...) over a generator expression or imap
(or, inversely, all(...) if there are "true" returns all the time).

Not that it improves clarity, but something like a dummy
reduce(lambda x, y: None, <genexp>, None) might (kind of) work for
arbitrary returns. Both variants only have a redundant boolean or None
value.
vbr



More information about the Python-list mailing list