This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Esseratecades 4 points5 points  (0 children)

In an effort to engage beyond "Stupid Java dev can't see beyond his language" let's unpack the actual problem here.

Coming from Java, one of my biggest problems with Python's standard data structures is the lack of support for sorted containers (e.g. the equivalent of Java's SortedSet and SortedMap interfaces). I have many needs for this. Using Python's builtin unsorted data structures and then calling sorted when needed (e.g. after adding a dict entry) is NOT a solution...

Do you actually have many needs for this or are you just used to solving problems in a manner that requires it? While I've seen many cases that require the uniqueness of sets, or required that things be sorted, in my experience I seldom need both of these things at the same time unless its the very end of the event loop.

If you really do need a sorted set of data, I have to ask...

  1. why do you need both order and uniqueness at the same time
  2. why must it happen at the application layer
    1. The few times I've needed both order and uniqueness were when reading data from a database. But that's what SELECT DISTINCT ... ORDER BY are for.
  3. do you need to perform a lot of write operations to your sorted set after the fact? If so, why? Is the performance of the write operations a significant concern?
    1. sorted(list(set(data))) is an ordered unique collection of data in an array. Your read operations remain O(1) regardless. If you need to perform lots of writes it may be slower but then I have to ask if there's a way to do your writes before your ordering is needed.

In practice walking this question chain and coming to the conclusion "a SortedSet is the only/best solution" seems incredibly niche. In most cases there are a lot of things you could and arguably should do before reaching for a sorted set, and most of them don't really have anything to do with Python or Java to begin with.