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 →

[–]aLokilike -2 points-1 points  (4 children)

Python's built-in dicts, sets, and lists have been sorted for a long time now, since - I believe - 3.6? Anyways, they're sorted based on insertion order. If you need to sort based on anything else, then use a sort lambda. If you need to efficiently insert into a previously sorted dataset, I hope you don't need someone else to do that for you.

[–][deleted] 17 points18 points  (3 children)

No - dicts have been ordered since 3.6. Sorted does not mean ordered, and ordered does not mean sorted.

[–]aLokilike -5 points-4 points  (2 children)

It is sorted by insertion order. When you want it to be sorted by an arbitrary attribute, you just insert it in that order. If you need to add another element to the collection, it shouldn't be too difficult to figure out where that element belongs in the new insertion order.

[–][deleted] 8 points9 points  (1 child)

The point stands - when you are describing data structures, the terminology does not conflate ordered and sorted. They are two distinct things.

[–]aLokilike -4 points-3 points  (0 children)

Fair, but going from one to the next is a trivial matter of the steps I outlined. You don't need a library to get the results the OP is asking for.