cosmologicon / pywat

Python wats
1.22k stars 99 forks source link

Solved "impossible" wat quiz example question 1 #4

Closed fxkr closed 8 years ago

fxkr commented 8 years ago

https://github.com/cosmologicon/pywat/blob/master/quiz.md

>>> x = [setattr(__import__('StringIO').StringIO, '__lt__', lambda self, other: True), __import__('StringIO').StringIO()][1]
>>> x<x
    True

Sure, it's a corner case, but it's a valid answer. It's legal by the letter of the rules, it's still just one expression, and it demonstrates that Python has operator overloading and so operators may not always do what you think they do.

fxkr commented 8 years ago

(An interesting variant of the question might be: ??? < ??? == True, but you have to substitute the same code at both places. Good solutions would be "object()" and something based on property(import("itertools")__.count)).

fxkr commented 8 years ago

Oh, sorry. @inglesp was faster.

Duplicate of #2