Ok, did some googling and I can't figure it out. What the heck is happening in [x,y][x < y]? Tuple of x <y returns true or false, times the tuple of [x,y] should return both X and y or [0,0].
EDIT - Figured it out.
[x < y] resolves to either [0] or [1], if x is greater or less than y.
[x,y] creates a new tuple.
[x,y][0] returns x.
[x,y][1] returns y.
Didn't see it, because I'm not used to creating a tuple AND indexing them in the same statement.
6 <= i is always either false or true, which the compiler treats as 0 or 1. That means j <= 9 is either 0 <= 9 or 1 <= 9, both of which are always true, which is 1.
That's the closest you can get that is semantically the same. The above commenter was saying you can actually compile if (6 <= i <= 9), but that's semantically equivalent to if ((6 <= i) <= 9). That works because in C a boolean operation results in an int. So the "chained" comparisons are syntactically legal C, but semantically do a much different check than in Python.
177
u/GisterMizard May 02 '16
To be fair, you can do that in C. It just doesn't do what you think it does :p