[Python-ideas] issubclass(collections.OrderedDict, collections.Sequence)

Ed Kellett edk141 at gmail.com
Wed Oct 8 07:53:11 CEST 2014


On 8 October 2014 05:37, Stephen J. Turnbull <stephen at xemacs.org> wrote:
> random832 at fastmail.us writes:
>
>  > This has nothing to do with comparable types
>
> "if ordering is the same" is what you wrote.  How do you propose to
> determine that without an OrderRelation type or similar?
>

If the order of the elements in the ordered container is the same -
which is easy to test for. In the interest of being exactly clear,
here's some code that does so (assuming I understand correctly). This
probably should be cleaned up, but gets the job done:

    def subordered(subset, superset):
        si = iter(superset)
        for x in subset:
            for y in si:
                if x == y:
                    break
            else:
                return False
        return True

    print(subordered([1, 4, 8, 9], range(10)))  # True
    print(subordered([1, 4, 9, 8], range(10)))  # False


edk


More information about the Python-ideas mailing list