ordered-set icon indicating copy to clipboard operation
ordered-set copied to clipboard

Enhancement Request: raise exception when creating OrderedSet with duplicate entries

Open gdlxn-ibm opened this issue 1 year ago • 0 comments

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.

gdlxn-ibm avatar Oct 31 '24 21:10 gdlxn-ibm