News for hackers. Stuff that matters.
Re:Python dicts are now ordered by BiteCode_dev on Friday February 07, 2020 @01:32PM (#22269095)
I live in the Python bubble, so I haven't realized until this post that so few people knew about that.

This post is massively popular despite talking about a feature we had since Python 3.6, in 2016, that was posted on HN at the time and that is featured in most popular tutorials.

A good reminder that most of the world doesn't revolve about my favorite language. And that information is not that fast to spread.

Re:Python dicts are now ordered by rplnt on Friday February 07, 2020 @01:55PM (#22269364)
> about a feature we had since Python 3.6, in 2016

No, you had that feature in one implementation. Now it's in the language specification. That's vastly different because only now you can rely on it without fearing it can go away with the next release.

Re:Python dicts are now ordered by BiteCode_dev on Friday February 07, 2020 @02:03PM (#22269480)
First, cPython is 99% of Python deployments. So much that if a script works on it but not on another implementation, people often consider the later broken.

As this post proves that most people don't even know about this feature, you can be pretty sure the vast majority of people don't know about pypy, micropython, etc.

Secondly, even if you want to nit pick, Python 3.7 made it official more than one year ago. We are currently in the 3.9 alpha.

In fact, 3.7 didn't touch the implementation, just merely declared "yep, good idea, let's keep it that way".

Re:Python dicts are now ordered by squeaky-clean on Friday February 07, 2020 @02:43PM (#22270006)
There's also the indication that this is official, and not just an implementation quirk. I still used OrderedDict in 3.6 because there was no guarantee 3.7 (or later) wouldn't silently break ordering on the standard dict. At least now it's unlikely to change because it will be considered a breaking change.
Re:Python dicts are now ordered by d0mine on Friday February 07, 2020 @03:03PM (#22270268)
BDFL declared Python dict to be ordered in 2017 — It can't be more official than that for Python https://mail.python.org/pipermail/python-dev/2017-December/1... i.e., Python 3.7 (whatever implementation must keep the insertion order). CPython keeps the order since Python 3.6. Pypy even before that.
Re:Python dicts are now ordered by user5994461 on Friday February 07, 2020 @05:01PM (#22271490)
A barely legible email dump with 50 concurrent answers is supposed to be the clear official statement?

Not to mention that developers just begin migrating to python 3 in 2017 and code still had to work on 2.7 that doesn't order.

Re:Python dicts are now ordered by anderskaseorg on Friday February 07, 2020 @05:12PM (#22271632)
The official release notes for the following release is certainly a clear official statement.

https://www.python.org/downloads/release/python-370/

“The insertion-order preservation nature of dict objects is now an official part of the Python language spec.” (June 27, 2018)

Re:Python dicts are now ordered by true_religion on Friday February 07, 2020 @05:03PM (#22271522)
I knew about it, because everyone was talking about it. The origination of the actual information is irrelevant. It was basically interesting gossip for a few weeks.
Re:Python dicts are now ordered by d0mine on Saturday February 08, 2020 @11:56AM (#22276740)
The ruling is the very first and only line from the link:

> Make it so. "Dict keeps insertion order" is the ruling. Thanks!

Re:Python dicts are now ordered by dr_zoidberg on Friday February 07, 2020 @07:19PM (#22272632)
There's a great talk by David Beazley[0], which I don't remember its title right now, where he bashes all previous python versions except the latest at the time[1], which was 3.6. And he says "since I'm not a core developer, I can tell you this: rely on dicts being ordered so much that eventually they'll make it official". Guess he "won" in the end ;)

[0] Well, he usually gives great talks anyway

[1] Alright, he literally started many talks doing that

Re:Python dicts are now ordered by crashbunny on Saturday February 08, 2020 @08:35AM (#22275630)
Raymond Hettinger does or did a few talks on dictionaries too. He covers the history of dictionaries in python and how they evolved. It was mentioned in the article's comment section.

https://www.youtube.com/watch?v=p33CVV29OG8

Re:Python dicts are now ordered by DonHopkins on Friday February 07, 2020 @09:31PM (#22273392)
Yes, David Beazley's talks are always wonderful!
Re:Python dicts are now ordered by jeen02 on Saturday February 08, 2020 @08:45AM (#22275658)
Whoa, calm your horses angry boy.
Re:Python dicts are now ordered by takeda on Friday February 07, 2020 @03:42PM (#22270698)
That still was announced a while ago. When reading the title I though it was something new (maybe now Python decided to keep the keys sorted? ;)
Re:Python dicts are now ordered by jimmaswell on Friday February 07, 2020 @06:27PM (#22272303)
> rely on it without fearing it can go away with the next release

This is Python we're talking about.

Re:Python dicts are now ordered by yvdriess on Friday February 07, 2020 @02:38PM (#22269928)
There is no language spec for Python, the CPython implementation defines the language.
Re:Python dicts are now ordered by xapata on Friday February 07, 2020 @04:12PM (#22271021)
The language reference is a specification for the language. The library reference is a specification for the standard library.

https://docs.python.org/3/reference/index.html

Re:Python dicts are now ordered by gshulegaard on Friday February 07, 2020 @04:10PM (#22270992)
I have lived in Python ~80% of my career (~50% now) currently), although a large chunk of my career was writing 2.7 compatible with 2.6 (thanks RHEL). For the last year and a half I have written 3.6+ exclusively and I didn't realize that regular dicts were now ordered.

I don't use dicts if I require ordering, but if I did I would probably still reach for collections.OrderedDict...

I wonder what the implications are of dict ordering with the "new" (new for me...) function args and *kwargs...from the hip it sounds pretty handy.

Re:Python dicts are now ordered by int_19h on Friday February 07, 2020 @08:02PM (#22272887)
The implications are that now you get to see the order in which keyword args were specified by the caller. And in classes, you get to see the order in which attributes were defined. Both can come in very handy.
Re:Python dicts are now ordered by BiteCode_dev on Saturday February 08, 2020 @12:49AM (#22274186)
Dict ordering started from the need to have class attributes, args and kwargs ordered if I recall.
Re:Python dicts are now ordered by xapata on Saturday February 08, 2020 @02:16AM (#22274466)
No, that was a happy coincidence. The goal of the dict implementation was efficiency. Ordering was a side-effect.
Re:Python dicts are now ordered by ineedasername on Friday February 07, 2020 @07:58PM (#22272869)
Most of the python I've written and maintain (which, honestly, isn't too much) was 2.7, so it is news to me too. Nice!