If you want to compare two sets, you can safely use set1 = set2 . Set items are compared using equality. Two sets are equal if they contain equal objects.
Sorting them does not make sense for comparing equality.
Note that Set Equality is implemented (roughly) as follows:
- if both sets are the same size
- if all elements of set2 are included in set1
->, since they are the same size, and all elements of set1 are in set2, they must be equal.
Johan b
source share