# Add \`OrderedSet\` to stdlib

**URL:** <https://discuss.python.org/t/add-orderedset-to-stdlib/12730>\
**Category:** Ideas\
**Created:** [December 24, 2021, 2:59pm UTC](https://discuss.python.org/t/add-orderedset-to-stdlib/12730 "2021-12-24T14:59:00Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![jagerber](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jagerber/32/9412_2.png) [@jagerber](https://discuss.python.org/u/jagerber)\
**Post date:** [October 22, 2022, 4:03pm UTC](https://discuss.python.org/t/add-orderedset-to-stdlib/12730/11 "2022-10-22T16:03:50Z")

</div>

@steven.daprano Thank you so much for your great overview of the downsides of external dependencies. Indeed I just submitted a request with the security team at my organization to include external ordered set packages in our internal repo which will take some time to process. Getting the dependencies included on commercial projects will also require time and discussions. Another downside I encountered is, because of whatever quirk of my environment I ran into `C` related errors when I tried to `pip install` the cython `orderedset` package. Suffice it to say I am having to pay a time cost to include `OrderedSet` in my project. And the question remains, why must I pay a cost for `OrderedSet` but not `OrderedDict`?

@ajoino I don’t think the need for ordered sets needs to be justified. There are already packages available dedicated to providing ordered set functionality so clearly folks want them for something. Nonetheless, I’ll provide my use case for posterity and conversation fodder. I have an object which has tags (strings) that are dynamically added to the object. But the tags are unique so it is very convenient to have a `tag.add('tag_0')` api. To get uniqueness with a list I would have to do a manual check, and as has been mentioned already, there is a performance hit with a list compared to a set (though performance at this junction is not a concern for my specific present use case). Now, these tags are generated in the order of specific user input data and after being generated, the tags will be used to label data processing output (printouts, plots, etc.) and, for convenience, the user will expect the data printouts to be in the same order as the tags were generated. This could of course be accomplished without ordered sets (for example I could include new attributes which remember the order of tag inputs and then pull these in later) with slightly more overhead but ordered sets are a very natural and convenient solution.

So for my use case I would like a data structure whose elements are unique and whose elements are ordered. Lists and tuples are ordered but do not have unique elements. Sets have unique elements but are unordered. So my use case calls for a different collection type, the `OrderedSet` which many others have found uses for. I don’t see any reason why this container type shouldn’t be in `collections` next to `OrderedDict`. wrt the “fancy list” conversation: `OrderedSets` are fancy lists in that they have element uniqueness and `OrderedSets` are also fancy sets in that their elements are ordered. But the fact that ordered sets are “fancy something elses” doesn’t, to me, have any bearing on if they should be included in the standard library or not…

---

_[View the full topic](https://discuss.python.org/t/add-orderedset-to-stdlib/12730)._
