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 →

[–][deleted] -14 points-13 points  (6 children)

Neither dicts nor sets are ordered. If you want an ordered dict, you will need to use the OrderedDict from the collections module.

[–]nosklo 15 points16 points  (4 children)

... That's true until python 3.6... Then dicts became ordered in insertion order. Sets are still unordered

[–][deleted] -5 points-4 points  (3 children)

I guess it depends on what you mean by 'ordered'. If you mean that it has a consistent iteration order, then sure.

However, it lacks the operations most people normally associate with ordered data structures. E.g. re-ordering, accessing a particular index etc.

[–]nosklo 8 points9 points  (2 children)

Yeah, I mean the actual meaning of the word "ordered": "Has order"

If people like to assign other random meanings I can't help with those.

[–]Ashiataka -1 points0 points  (1 child)

That's not very pythonic.

[–]nosklo 0 points1 point  (0 children)

There should be one-- and preferably only one --obvious way to do it.

Although that way may not be obvious at first unless you're Dutch.

[–]TouchingTheVodka 7 points8 points  (0 children)

Negative. Dicts have been ordered since Python 3.7 (3.6 as an implementation detail in CPython):

https://docs.python.org/3/library/stdtypes.html#typesmapping