[openstack-dev] "if X not in Y" vs. "if not X in Y" consensus?
Monty Taylor
mordred at inaugust.com
Thu Jan 31 19:41:03 UTC 2013
On 02/01/2013 04:39 AM, Pitucha, Stanislaw Izaak wrote:
> 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
That is definitely both something I never expected to need, and the
oddest/coolest thing I believe my brain can possibly handle this early
in the morning.
> 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
>
>
>
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
More information about the OpenStack-dev
mailing list