I have two OrderedSets and I'm trying to check whether one in a subset of the other - both the elements and their order is important. However, the orderedset package is giving me strange 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 b
contains a value (69
) that is definitely not in a
. Why is a
a superset
of b
then?
However, when I try this:
>>> c = orderedset.OrderedSet([1, 2, 3])
>>> d = orderedset.OrderedSet([1, 2, 4])
>>> c.issuperset(d)
False
This behaviour seems inconsistent to me: why should the choice of values - [433, 316, 259]
versus [1, 2, 3]
- in the OrderedSet affect the output of issuperset()
?
Perhaps there's a better way to do this? I need to know whether the elements in b
are contained in a
in the same order. Meaning that, if
a = OrderedSet([433, 316, 259])
I'm looking for partial matches within that set that start with the same starting value as a
(433
). This is what I want out of it:
OrderedSet([433, 316, 259])
OrderedSet([433, 316]])
OrderedSet([433])
And not:
OrderedSet([433, 259])
OrderedSet([316, 259])
OrderedSet([433, 316, 69])
OrderedSet([433, 259, 316])
OrderedSet([259, 433])
...
Basically, if this really confusing - I have an ordered set and I'm trying to find partial matches both in terms of the values and their order.