Which is faster? (if not b in m) or (if m.count(b) > 0)

Delaney, Timothy (Tim) tdelaney at avaya.com
Sun Feb 19 20:31:59 EST 2006


Jean-Paul Calderone wrote:

> Not since Python 2.4:
> 
>     >>> dis.dis(lambda: x not in y)
>       1           0 LOAD_GLOBAL              0 (x)
>                   3 LOAD_GLOBAL              1 (y)
>                   6 COMPARE_OP               7 (not in)
>                   9 RETURN_VALUE
>     >>> dis.dis(lambda: not (x in y))
>       1           0 LOAD_GLOBAL              0 (x)
>                   3 LOAD_GLOBAL              1 (y)
>                   6 COMPARE_OP               7 (not in)
>                   9 RETURN_VALUE
>     >>>

Damn - I missed that change. Peephole optimiser I guess.

Tim Delaney



More information about the Python-list mailing list