记录一些看到的,让我感叹“卧槽天才”的东西
比不上人家五年前的程度……
[1/2/2013] Challenge #115 [Easy] Guess-that-number game!


Q: What exactly is happening in that line? How do the '[' and ']' characters differ from ordinary parentheses?
A: n>r evaluates to 0 if it's false, and to 1 if its true.
With ['below', 'above'] we create a list with two elements.
Now by typing ['below', 'above'][n>r] we access the first or second element of the list, depeding on what n>r evaluates to.
网友评论