Is there a more elegant way to express ((x == a and y == b) or (x == b and y == a))? December 26, 2022 by Tarik If the elements are hashable, you could use sets: {a, b} == {y, x}