[Python-ideas] custom predicate for all() & any()

Sven R. Kunze srkunze at mail.de
Tue Mar 29 09:15:21 EDT 2016


On 26.03.2016 18:04, Terry Reedy wrote:
> So proposed all(iterable, predicate) ==  all(map(predicate, iterable))

I am no native English speaker. Is predicate the right word for this?


Two observations:
1) I recently saw a similar request to another "aggregate" function.
2) I can comprehend why all(map(predicate, iterable)) is harder to 
write. However, somehow I feel all(iterable, predicate) is harder to 
maintain.

Because of 2) I am -1 on this. :)


One could further argue that we need a another "predicate" for 
filtering: all(iterable, map, filter) etc.
I get the feeling we would rebuilding things over and over again: list 
comprehensions, filter, map, itertools, for-loops etc.

What about "sum", "max" etc? They all could need map + filter.


Additional thought:

I think the underlying issue is the number of parentheses involved. I 
myself somehow avoid nesting too many function calls into one line just 
because of that; not because of the complexity involved but because it 
looks strange. Of course the number of parentheses involved is an 
indicator of the complexity. Not sure if there is another way of 
handling this; maybe piping or something. Would be great if we could 
avoid writing ))) or ))))).

Best,
Sven


More information about the Python-ideas mailing list