On Fri, Aug 30, 2013 at 5:15 PM, Antoon Pardon
<antoon.par...@rece.vub.ac.be> wrote:
> Op 30-08-13 06:55, Ben Finney schreef:
>> Ben Finney <ben+pyt...@benfinney.id.au> writes:
>>
>>> Fábio Santos <fabiosantos...@gmail.com> writes:
>>>
>>>> It is a shame that this is not possible in python. for..if exists in
>>>> comprehensions and not in regular loops but that would be nice
>>>> sometimes.
>>>     for foo in (spam for spam in sequence if predicate(spam)): …
>>
>> Better:
>>
>>     for foo in filter(predicate, sequence):
>>         process(foo)
>
> Well better in what way? You now have to translate a predicate
> expression into a predicate function. Which AFAIU was one of
> the reasons to move away from map/filter to list comprehension.
>
> As I understand it, python made a move away from map and filter
> towards list comprehension. Chris seems to want some of the
> possibilities that came with that incorporated into the for
> statement. And your suggestion is to go back to the old kind
> of filter way.

No, actually Ben's quite right - assuming the predicate is a simple
function, of course (Python's lambda notation is a bit clunky for
comparisons); as of Python 3, filter() is lazy and is pretty much what
I'm doing here. However, that's still a specific answer to a specific
(albeit common) instance of wanting to merge control structures.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to