I want to compare sets in a match expression in Python.
So imagine you want to compare multiple variables but they do not have any order. They only have to include the same values as a whole. In this case you should use match if you have multiple combinations you want to test for the sake of readiness. That could look like the following:
match set((string1, string2, string3)):
case set((' Hello', ' world', '!')):
...
case set(('beatufiful', 'fair', 'nice')):
...
case set(('extremly', 'hyper', 'strongly')):
...
However, this approach does not work and now I fear I it may not be possible to compare sets this way. Comparing through '{'...',...}' expressions gives a syntax error. However comparing the following way works:
match 1:
case 1 if set((' Hello', ' world', '!')) == set((string1, string2, string3)):
...
case 1 if set(('beautiful', 'fair', 'nice')) == set((string1, string2, string3)):
...
case 1 if set(('extremely', 'hyper', 'strongly')) == set((string1, string2, string3)):
...
(I tested it accurately, for every (special) occasion with unittest.)
But this is not the best approach for the unnecessary code.
So how do I get to a cleaner variant?
if/elif?matchstatements aim to exploit.