[Python-ideas] Parametrized any() and all() ?

Tarek Ziadé tarek at ziade.org
Wed Jan 16 15:52:19 CET 2013


On 1/16/13 3:10 PM, Steven D'Aprano wrote:
> On 16/01/13 22:10, Nick Coghlan wrote:
>> On Wed, Jan 16, 2013 at 8:44 PM, Tarek Ziadé<tarek at ziade.org>  wrote:
>>> On 1/16/13 11:33 AM, Laurens Van Houtven wrote:
>>>>
>>>> Hey Tarek,
>>>>
>>>> I would write that as any(x is None for x in it)
>>>
>>>
>>> But here you're building yet another iterable to adapt it to any(), 
>>> which
>>> seems to me overkill if we can just parametrized the loop in any()
>>
>> Such a micro-optimization isn't worth the cost of adding a second way
>> to do it that everyone will then need to learn.
>
>
> For all
> we know, adding a filter function will be a pessimization, not an 
> optimization,
> using more memory and/or being slower than using a generator 
> expression. It
> certainly isn't clear to me that creating a generator expression like
> (x is None for x in it) is more expensive than creating a filter 
> function like
> (lambda x: x is None).
>
> -1 on adding a filter function.

I abandoned the idea,

but I'd be curious to understand how creating several
iterables with one that has an 'if', can be more efficient than having a 
single
iterable with an 'if'...


>
>
>


-- 
Tarek Ziadé · http://ziade.org · @tarek_ziade




More information about the Python-ideas mailing list