PEP218: Representing the empty set

Paul Rubin http
Tue Feb 17 17:32:02 EST 2004


Peter Hansen <peter at engcorp.com> writes:
> I think the example I would have in mind is a comparison:
> 
> if a == []:
>     # do something
>     if b != {}:
>         a.append(b)
> 
> or whatever....  If the empty item
> is merely a temporary, to be used and discarded, then the apparent
> extra overhead of the call, and the less succinct syntax, lead me to
> think the short form is preferable.

But you suffer the overhead either way.  The {} syntax may be worse
than the function call syntax because it looks like it avoids the
overhead when it really doesn't.  The correct way to avoid the
overhead is with "if len(b) != 0: ... ".



More information about the Python-list mailing list