2010/2/1 Gerald Britton <gerald.brit...@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 -- http://mail.python.org/mailman/listinfo/python-list