ordered-set
ordered-set copied to clipboard
Enhancement Request: raise exception when creating OrderedSet with duplicate entries
Currently (ordered-set 4.1.0), OrderedSet removes duplicates when both creating an OrderedSet with duplicates or when adding a duplicate element to an existing OrderedSet:
>>> s = OrderedSet([1, 1, 2, 3, 2]) >>> s
OrderedSet([1, 2, 3]) >>> s.add(1) 0 >>> s OrderedSet([1, 2, 3])
What I'd like is an option, say FailOnDuplicate, that would raise an exception, say ValueError, when an OrderedSet is created with duplicate elements. That is, both
s = OrderedSet([1, 1, 2, 3, 2], FailOnDuplicate=True)
and
s = OrderedSet([1, 2, 3]) s.add(1)
should raise ValueError.
I realize that the Python built-in *set and frozenset have the same behavior. I think adding a similar option to set and frozenset would also be useful.