Writing this as a list comprehension would be a lot clearer: `[(expr, v) for expr, v in mapping if expr == x]`, which suggests further simplification by extracting `unnecessary_permutations` before sorting `mapping` (i.e. `unnecessary_permutations` is then just `[(x, mapping[x])]`)