On 22/03/2020 19:59, Steve Jorgensen wrote:
Currently, the `issubset` and `issuperset` methods of set objects accept arbitrary iterables as arguments. An iterable that is both a subset and superset is, in a sense, "equal" to the set. It would be inappropriate for `==` to return `True` for such a comparison, however, since that would break the `Hashable` contract.
Should sets have an additional method, something like `like(other)`, `issimilar(other)`, or `isequivalent(other)`, that returns `True` for any iterable that contains the all of the items in the set and no items that are not in the set? It would therefore be true in the same cases where `<set> = set(other)` or `<set>.issubset(other) and <set>.issuperset(other)` is true.
You worded the above carefully, but it may not be universally obvious that <set>.isequivalent(other) == True does not imply len(<set>) == len(other) (assuming `other` has a len() method), e.g. <set> = set("a") other = list("aa") I think this point should be documented, lest someone interpret `isequivalent` as "equals".
A similar point holds with the existing `issuperset` method (a set can be shorter than something it is a superset of), but I think there would be more danger of confusion with this new method.
+0 on the proposal Rob Cliffe