Unexpected behavior in Python OrderedSet.issuperset ()

I have two OrderedSets, and I'm trying to check if one of the subsets of the other is both the elements and their order are important. However, the orderedset package gives me weird results.

>>> import orderedset
>>> a = orderedset.OrderedSet([433, 316, 259])
>>> b = orderedset.OrderedSet([433, 316, 69])
>>> a.issuperset(b)
True

This doesn't make any sense to me because it bcontains a value ( 69) that is definitely not in a. Why aa supersetof b, then?

However, when I try to do this:

>>> c = orderedset.OrderedSet([1, 2, 3])
>>> d = orderedset.OrderedSet([1, 2, 4])
>>> c.issuperset(d)
False

This behavior seems inconsistent to me: why does the choice of [433, 316, 259]versus values [1, 2, 3]in the OrderedSet affect the output issuperset()?

Perhaps there is a better way to do this? I need to know if elements are in bin ain the same order. This means that if

a = OrderedSet([433, 316, 259])

, , a (433). , :

OrderedSet([433, 316, 259])
OrderedSet([433, 316]])
OrderedSet([433])

:

OrderedSet([433, 259])
OrderedSet([316, 259])
OrderedSet([433, 316, 69])
OrderedSet([433, 259, 316])
OrderedSet([259, 433])
...

, - , , .

+4
1

, Python .

github , issuperset

def issuperset(self, other):
    return other <= self

, :

def __le__(self, other):
    if isinstance(other, _OrderedSet):
        return len(self) <= len(other) and list(self) <= list(other)

, , <= Python . <=, , .

, [433, 316, 259] [433, 316, 69] ( ), [433, 316, 259] [433, 316, 260] ( , ).

, , , ,

return len(self) <= len(other) and set(self) <= set(other)

<=, Python, .

.

+4

All Articles