[openstack-dev] "if X not in Y" vs. "if not X in Y" consensus?
Pitucha, Stanislaw Izaak
stanislaw.pitucha at hp.com
Thu Jan 31 17:39:42 UTC 2013
Even better - it's actually special-cased and "x not in y" is exactly
equivalent to "not x in y".
Check out dis module:
In [13]: dis.disassemble((lambda a, b: a not in b).func_code)
1 0 LOAD_FAST 0 (a)
3 LOAD_FAST 1 (b)
6 COMPARE_OP 7 (not in)
9 RETURN_VALUE
In [14]: dis.disassemble((lambda a, b: not a in b).func_code)
1 0 LOAD_FAST 0 (a)
3 LOAD_FAST 1 (b)
6 COMPARE_OP 7 (not in)
9 RETURN_VALUE
(useful if your "not in" is faster or means something different than negated
"in" - for example bloom filters, etc.)
#things_you_never_expected_to_need
Regards,
Stanisław Pitucha
Cloud Services
Hewlett Packard
-----Original Message-----
From: Dean Troyer [mailto:dtroyer at gmail.com]
Sent: Thursday, January 31, 2013 4:20 PM
To: OpenStack Development Mailing List
Subject: Re: [openstack-dev] "if X not in Y" vs. "if not X in Y" consensus?
On Thu, Jan 31, 2013 at 9:57 AM, Vishvananda Ishaya <vishvananda at gmail.com>
wrote:
> The in operator has precedence over not so to have not be an operator
> on X you would need:
>
> (not X) in Y
Ugh.
"It's morning" I thought
"I'll just look this up" I thought
"Yup, 'boolean not' is above 'in' (and the other operators) in the table" I
thought, without actually looking at the table and noticing that it's
backwards from every other operator precedence table I've looked at and
written "Python can't have more than one way to do this" I thought
Wrong.
/me going back to get more caffeine...
dt
--
Dean Troyer
dtroyer at gmail.com
_______________________________________________
OpenStack-dev mailing list
OpenStack-dev at lists.openstack.org
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 6216 bytes
Desc: not available
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20130131/da25e711/attachment.bin>
More information about the OpenStack-dev
mailing list