This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Dictionary assignment shorthand
Type: enhancement Stage: resolved
Components: Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, davidhariri
Priority: normal Keywords:

Created on 2021-05-20 14:40 by davidhariri, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg394027 - (view) Author: David Hariri (davidhariri) Date: 2021-05-20 14:40
In some languages, one may declare a dictionary's key and its value like so:

```
foo = "bar"

my_dict = { foo }
>> { "foo" : "bar" }
```

In Python, one must instead write:

```
foo = "bar"

my_dict = {
    "foo": foo
}
>> { "foo" : "bar" }
```

I humbly suggest this change as a QoL improvement for those who work with dictionaries all day.
msg394029 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-05-20 14:46
Your proposal is not possible in Python. The object does not know under which variable names it is accessible. The closest you can get is this:

>>> dict(
...     foo="bar"
... )
{'foo': 'bar'}
History
Date User Action Args
2022-04-11 14:59:45adminsetgithub: 88356
2021-05-21 19:24:58terry.reedysetstatus: open -> closed
resolution: rejected
stage: resolved
2021-05-20 14:46:18christian.heimessetnosy: + christian.heimes
messages: + msg394029
2021-05-20 14:40:20davidhariricreate