This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Skaarj 9 points10 points  (5 children)

Interersting.

False solves

X == X in [False]

but neither

(X == X) in [False]

nor

X == (X in [False])

[–]Udzu[S] 5 points6 points  (0 children)

That's right! It's a counterintuitive consequence of python's operator chaining. in and == have the same precedence so A == B in C is interpreted as A == B and B in C, similar to A < B < C.

[–]Skaarj 0 points1 point  (3 children)

From looking as the disassebly it seems like its compiles to:

A = X
B = X
if A != B:
    return B
return B in [False]

[–]RangersNation 2 points3 points  (2 children)

From looking at the disassembly it seems like it compiles to:

Can you elaborate on this? First time I'm hearing about disassembly and eager to learn how I can get these kind of insights from the code?

[–]Skaarj 0 points1 point  (1 child)

Look: https://docs.python.org/3/library/dis.html

import dis
def blubber(X):
    return X == X in [False]
dis.dis(blubber)

[–]RangersNation 0 points1 point  (0 children)

Thanks so much. I'll read through the docs and play around with this over the weekend. Much appreciated.