[Python-ideas] Adding an optional function argument to all() and any() builtins

Alexander Belopolsky alexander.belopolsky at gmail.com
Sun Nov 21 21:43:52 CET 2010


On Sun, Nov 21, 2010 at 3:20 PM, Masklinn <masklinn at masklinn.net> wrote:
> On 2010-11-21, at 21:11 , MRAB wrote:
>>
>> if any(mytestfunction(i) for i in mylist):
>>    foo()
>
> is not an improvement over `if any(map(mytestfunction, mylist))` or `if any(imap(mytestfunction, mylist))`

In 2.7, both MRAB's generator expression solution and your imap() are
improvements over map() because they don't create a temporary list.
In 3.x, map = imap, but generator expression is more readable IMO.



More information about the Python-ideas mailing list