Search code examples
pythondata-structuressetpython-typing

Does collections.abc.Collection have a uniqueness property, like Set?


From https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes, it's clear to me that a collections.abc.Set is a collections.abc.Collection. And a useful property of Set is the uniqueness property (that it doesn't contain duplicated elements).

However, what I am trying to figure out is, does Collection have a uniqueness property?

In other words, is it possible for a Collection to have duplicate values inside?


Solution

  • However, what I am trying to figure out is, does Collection have a uniqueness property?

    No it doesn’t. All it declares are __contains__, __iter__, and __len__.

    Actually collections.abc.Set inherits from collections.abc.Collection then adds other features as Mixin Methods.

    See mixin method here on SO