Live data from Hacker News

Python dicts are now ordered

softwaremaniacs.org

211–220 of 457 posts

Re: Python dicts are now ordered

#211
post #75

Earlier quoted context omitted.

If your code relies on a minimum python version, you can add `python_requires=">=3.5"` to your setup.py [ https://packaging.python.org/guides/distributing-packages-us... ] to ensure it's not installed on older releases. That field itself is kinda new; but if needing to block users with older versions, that shouldn't be an issue.

personally, i just drop a f-string in setup.py and that'll filter out any python for which this issue pertains.

This might not work if you’re distributing a wheel.

Re: Python dicts are now ordered

#212
post #94

Earlier quoted context omitted.

My main issue with it is that if someone figures out an even better way to do dictionaries but it doesn't preserve insertion order, then that technique can't be used. But I certainly wouldn't call it a stupid decision, the problem is that once a behaviour is observable then people absolutely will start relying on it.

All they have to do is give it a different name, such as unordered_dict.

I might have preferred odict be added and dict left alone, so that you didn't have to import OrderedDict when really you just want the new dict. If dict and odict mapped to the same thing for a while, fine, but dict could diverge again if desired.

Re: Python dicts are now ordered

#213

This is an amazing contribution to the language. A mixture of speed and convenience, probably made by volunteers. As for people criticizing a change to what use to be a non-deterministic ordering of a dict iteration; I don't know what to say to them, other than, are you serious? There are people out there who are working for us, they work for free and they did some heavy lifting to give us this. They might read what…

People who bother to complain are those who actually care about your thing. People who do not care simply leave without ever telling you why. Your complainers are often your most dedicated and invested users.

Though in this specific case, my sense has been that your complainers are often your most dedicated and invested users of a version of the language that was officially retired 38 days ago.

Python is just bizarrely political. I suspect that it's now cursed for all time to have every future PEP become a battle in a proxy war over PEP 3000.

Re: Python dicts are now ordered

#214

I think this change is great, but this really only becomes news again once all major LTS are shipping with at least Python 3.7, right? No one can really use it in code they plan to distribute at the moment. Maybe I am underestimating the amount of Python code that is meant for internal or personal use only.

We've been running FROM python:3.7 in production for months. Works just fine. ;)

Re: Python dicts are now ordered

#215
post #94

Earlier quoted context omitted.

All they have to do is give it a different name, such as unordered_dict.

Which means no one gets it for free when it is added to the language.

You could add an ordered dict by a different name and also have dict be the more efficient ordered version so that people get the efficiency gain for free but don't have to worry and forward compatibility.

Re: Python dicts are now ordered

#216
post #164

Earlier quoted context omitted.

Other languages don't generally have special order guarantees about standard maps. This seems very idiosyncratic.

std::map in C++ stores keys in order. You have to use std::unordered_map to not get that behavior.

Yes, but that’s different kind of order. Python dicts order is insertion order, while std::map is key order.

Re: Python dicts are now ordered

#217
1) I am personally annoyed as someone who has had to unwind knotty dict soup python codebases.

2) This will make life easier for thousands of programmers and prevent a massive number of extremely difficult bugs from hurting users.

Re: Python dicts are now ordered

#218

It seems people dont realize that you can have your cake and eat it too. You can have both orderered and unordered maps in the same language: https://yaml.org/type/map https://yaml.org/type/omap No reason to argue about which one to make "dict". In fact it would be better to have both because youre taking a performance hit (a significant one) by ordering the entries.

The new dict does not come with a performance hit, let alone a significant one. It’s much more memory efficient and generally slightly faster.

Re: Python dicts are now ordered

#219

Earlier quoted context omitted.

As it’s widely known, more often than not “criticism” of open source software quickly devolves into hate and toxicity. Helpful criticism is great but be careful with defending the “criticism culture” around foss, it’s often angry unhappy people that want it all for free on a golden platter, and yesterday.

That does not matter, nothing is above criticism.

It does matter. If people get hate for doing work on open source they will stop doing work on open source. Yes you can be critical of everything, but the hate that some people spew toward certain open projects is not only nauseating but actively damaging to the community.

Re: Python dicts are now ordered

#220
post #164

This is an amazing contribution to the language. A mixture of speed and convenience, probably made by volunteers. As for people criticizing a change to what use to be a non-deterministic ordering of a dict iteration; I don't know what to say to them, other than, are you serious? There are people out there who are working for us, they work for free and they did some heavy lifting to give us this. They might read what…

Other languages don't generally have special order guarantees about standard maps. This seems very idiosyncratic.

Users of JSON, probably the most common data interchange format on the planet, frequently have implicit requirements about key ordering. It is highly convenient to be able to parse a JSON string into a native Python data structure, add a field, emit it back, and preserve the ordering.
Post reply on HN