Is there a more elegant way to express ((x == a and y == b) or (x == b and y == a))?

LetEpsilonBeLessThanZero picture LetEpsilonBeLessThanZero · Oct 17, 2019 · Viewed 11.3k times · Source

I'm trying to evaluate ((x == a and y == b) or (x == b and y == a)) in Python, but it seems a bit verbose. Is there a more elegant way?

Answer

Dani Mesejo picture Dani Mesejo · Oct 17, 2019

If the elements are hashable, you could use sets:

{a, b} == {y, x}