Live data from Hacker News

Python dicts are now ordered

softwaremaniacs.org

1–10 of 457 posts

Re: Python dicts are now ordered

#2
"Ordered dict" is ambiguous, and from the title I thought that key order was meant. Reading the article, I see that it's actually insertion order. Which makes much more sense. Key order would have been a much more significant change.

Re: Python dicts are now ordered

#4
post #3

Javascript taught me to never assume any ordering in a dict/map/hashmap (whatever the term)

Is the ordering there at least fixed, or can it vary from run to run even on the same data, or between implementations or versions of the same implementation?

EDIT: to clarify, I was asking about JavaScript there.

Re: Python dicts are now ordered

#6
post #4
post #3

Javascript taught me to never assume any ordering in a dict/map/hashmap (whatever the term)

Is the ordering there at least fixed, or can it vary from run to run even on the same data, or between implementations or versions of the same implementation? EDIT: to clarify, I was asking about JavaScript there.

[deleted]

Re: Python dicts are now ordered

#7
post #3

Javascript taught me to never assume any ordering in a dict/map/hashmap (whatever the term)

Well, JavaScript Map preserves insertion order when iterating entries, and as of ES2015 (i.e. ES6), for-in also iterates the (string, non-numeric) properties of an object in insertion order.

Re: Python dicts are now ordered

#9
post #4
post #3

Javascript taught me to never assume any ordering in a dict/map/hashmap (whatever the term)

Is the ordering there at least fixed, or can it vary from run to run even on the same data, or between implementations or versions of the same implementation? EDIT: to clarify, I was asking about JavaScript there.

It is deterministic, but it's an odd rule-set. For example: `var o = { 3: 'foo', 1: 'bar', b: 'baz', a: 'quux' }` Will yield: `{1: "bar", 3: "foo", b: "baz", a: "quux"}`.

Numeric keys get sorted. String keys are insertion-order. If key order is a priority, a Map should be used instead. Often when JavaScript's objects are used and a particular sort order is required, an accompanying (sorted) array is used.

Re: Python dicts are now ordered

#10
This is a solid argument for why you should have more datatypes available to you. If your program relies on an insertion order, say so. If anyone ever moves to another implementation, they will thank you for it.
Post reply on HN