pythonboolean-logic

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


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?


Solution

  • If the elements are hashable, you could use sets:

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