[Python-ideas] Is there any idea about dictionary destructing?
Guido van Rossum
guido at python.org
Tue Apr 10 11:20:11 EDT 2018
Here's one argument why sequence unpacking is more important than dict
unpacking.
Without sequence unpacking, you have a long sequence, to get at a specific
item you'd need to use indexing, where you often end up having to remember
the indices for each type of information. Say you have points of the form
(x, y, z, t), to get at the t coordinate you'd have to write p[3]. With
sequence unpacking you can write
x, y, z, t = p
and then you can use the individual variables in the subsequent code.
However if your point had the form {'x': x, 'y': y, 'z': z, 't': t}, you
could just write p['t']. This is much more mnemonic than p[3].
All the rest follows -- after a while extended forms of iterable unpacking
start making sense. But for dicts the use case is just much less common.
(If you're doing a lot of JSON you might have a different view on that. You
should probably use some kind of schema-guided parser though.)
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180410/8c393943/attachment-0001.html>
More information about the Python-ideas
mailing list