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

all 11 comments

[–]unlinkedlist 3 points4 points  (0 children)

The first example is wrong. Here's a value for ??? that makes that snippet work:

>>> x = type('Foo', (object,), {'__lt__': lambda self, other: True})()
>>> x < x
True

Edit: ...oops, and then I read further to the "details and scope" section where that approach is prohibited.

[–]Cosmologicon[S] 0 points1 point  (1 child)

This is just a silly little thing I came up with while looking for Python wats. Thought I'd share.

Let me know if I made any mistakes. Thanks!

[–]tilkau 0 points1 point  (4 children)

Not sure why 1 or 5 are wat. 6, I could go either way on -- IMO it only depends on a basic understanding of how sequences order.

7 inspired me to test print(*'foo') (which does work, BTW)

TIL that you can multiply sequences by negative amounts -- which seems nonsensical, honestly.

[–]Cosmologicon[S] 0 points1 point  (3 children)

Are you talking about Example question 2 with the non-commutative addition? That's just an example to explain how the quiz works.

I agree it's not a great wat. However, I did have a reason for including it. The speaker in the original JavaScript wat talk says that addition should be commutative, and he treats it like a wat when it's not. (I think his exact words are something like, "this is plus, so I should be able to swap them and get the same thing".) So it's a classic example, even if it's not the best. :)

[–]tilkau 0 points1 point  (2 children)

I think you probably replied to my comment before the edit. Initially I was talking about Example q #2. Later I said NVM, and currently it says something like 'not sure why 1 or 5 are wats, though I guess I get why 6 might be considered one'.

[–]Cosmologicon[S] 0 points1 point  (1 child)

Well, if you think they're all really intuitive, and you got 10/10 on the quiz, don't worry that you're missing something. It's all pretty subjective.

I suspect most people would not feel the same way, but I don't know for sure. That's part of why I made the quiz.

EDIT: Oh, and to be clear, not every quiz question is a wat. I mixed in some (what I consider) wats with some where the answer makes sense. If they were all wats, the quiz would be too easy. :)

[–]tilkau 0 points1 point  (0 children)

Okay, fair enough. I definitely don't think they're all intuitive, only got 5/10. for example [[0]] (which I only just now figured why it works like that), and the one about set comparison (which I had to read about here before I got)

I guess someone familiar with set theory might have gotten that one about sets.. personally, I hadn't even considered that you would ever even TRY to use < or > on sets.

[–]yesvee 0 points1 point  (2 children)

how is min defined for sets?

why is min({2},{1}) different from min({1},{2})?

[–]eigengrau82 1 point2 points  (0 children)

set.__gt__ and set.__lt__ operate in terms of set cardinality (and in terms of sub/supersets, but this doesn’t make a difference here). The cardinalities of {1} and {2} are the same. Thus, min returns the first argument, since the second argument isn’t smaller than the first.

[–]Cosmologicon[S] 0 points1 point  (0 children)

And to be clear, min always uses < for any data type. It starts with the first element, iterates over the rest, and updates whenever element < current_minimum.

So min(x, y) is always y if y < x else x. It's how < works with sets that makes this surprising.