checking if two things do not equal None

Tim Chase python.list at tim.thechases.com
Sat Mar 29 21:19:06 EDT 2014


On 2014-03-30 10:17, Chris Angelico wrote:
> On Sun, Mar 30, 2014 at 9:46 AM, Tim Chase <tim at thechases.com>
> wrote:
>> Though am I correct that your iteration tests for equality, while
>> mine tests for identity?  Also, my version bails early in the
>> event quitting early is possible.  That's particularly useful in
>> the case of doing something like
>>
>>   if all(x() is None for x in [func1, func2, func3, costly_func]):
            ^^^
>>     do_something()
> 
> Presumably you mean to actually call those functions, as checking
> the identity of a costly function is still cheap :)

Which is what I do...calling only those necessary until the all/any
condition has been met. :-)

If you create the list of things to iterate over by calling them as
you create the list, then you don't save much of anything.  If you
only call until one of them breaks the any/all construct, you save
all the subsequent function calls.

-tkc







More information about the Python-list mailing list