You can use something similar to what you have:
sameness = (len({x, y, z}) == 1)
This allows you to use any number of variables. For instance:
variables = {x, y, z, a, b, ...} sameness = (len(variables) == 1)
Note. Creating a set means that each variable must be hashed and hashed values ββmust be saved, but all() with the generator expression is short-circuited and only tracks two values ββat a time. Therefore, in addition to its readability, the expression of the generator is more efficient.
zondo source share