Operator Precedence/Boolean Logic
Marko Rauhamaa
marko at pacujo.net
Thu Jun 23 05:57:26 EDT 2016
Lawrence D’Oliveiro <lawrencedo99 at gmail.com>:
> 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.
Marko
More information about the Python-list
mailing list