[Python-Dev] Guarantee ordered dict literals in v3.7? (original) (raw)
Paul G paul at ganssle.io
Sun Nov 5 13:57:19 EST 2017
- Previous message (by thread): [Python-Dev] Guarantee ordered dict literals in v3.7?
- Next message (by thread): [Python-Dev] Guarantee ordered dict literals in v3.7?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Scientific applications want something like
{'a': 10, 'b': "foo", 'c': {'this': b'123'}} as an ordered initializer for unboxed or typed (or both) data. In general, if dicts are ordered, they can be used for example as initializers for (nested) C structs.
I can understand why you'd want an ordered container, I just don't see why it must be a dict. Why can't it be:
OrderedDict(a=10, b='foo', c=OrderedDict(this=b'123'))
Is it just that you don't want to type OrderedDict that many times? If it's so important to provide ordered dictionary literals, I would think it's a no-brainer to give them their own literal syntax (rather than re-defining dicts to have guaranteed order). e.g.:
o{'a': 10, 'b': 'foo', 'c': o{'this': b'123'}
Then there is no backwards incompatibility problem and users can express whether order does or does not matter to them when initializing a container.
On 11/05/2017 01:39 PM, Stefan Krah wrote:
On Sun, Nov 05, 2017 at 01:14:54PM -0500, Paul G wrote:
I'm not entirely sure I understand the full set of reasoning for this - I couldn't really tell what the problem with OrderedDict is from the link Stefan provided. It seems to me like a kind of huge change for the language to move from arbitrary-ordered to guaranteed-ordered dict. The problem I see is that this introduces a huge backwards compatibility burden on all implementations of Python.
2. Someone invents a new arbitrary-ordered container that would improve on the memory and/or CPU performance of the current dict implementation I would think this is very unlikely, given that the previous dict implementation has always been very fast. The new one is very fast, too. Stefan Krah
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/paul%40ganssle.io
-------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: <http://mail.python.org/pipermail/python-dev/attachments/20171105/43454e92/attachment.sig>
- Previous message (by thread): [Python-Dev] Guarantee ordered dict literals in v3.7?
- Next message (by thread): [Python-Dev] Guarantee ordered dict literals in v3.7?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]