Operator Precedence/Boolean Logic

Jussi Piitulainen jussi.piitulainen at helsinki.fi
Sat Jun 25 02:46:10 EDT 2016


Lawrence D’Oliveiro writes:

> On Thursday, June 23, 2016 at 9:57:35 PM UTC+12, Marko Rauhamaa wrote:
>> Lawrence D’Oliveiro:
>> 
>>> On Thursday, June 23, 2016 at 9:11:05 PM UTC+12, Marko Rauhamaa wrote:
>>>> The __len__ method is not guaranteed to execute in O(1).
>>>
>>> So what is?
>> 
>> The __bool__ method is the appropriate place to implement an
>> efficient emptiness check. It might not be O(1) but it will be the
>> most efficient way to check for emptiness, or the class is badly
>> implemented.
>
> Saying “or the class is badly implemented” sounds like circular
> reasoning...

What are you thinking? If there's a better way to implement __bool__,
why shouldn't that better way have been used?



More information about the Python-list mailing list