妈耶,天才

2018-03-25  本文已影响0人  ylylhl

记录一些看到的,让我感叹“卧槽天才”的东西

比不上人家五年前的程度……

[1/2/2013] Challenge #115 [Easy] Guess-that-number game!

Easy enough in Python - y2bd a very cool, clean trick - nint22

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.

上一篇 下一篇

猜你喜欢

热点阅读