You can either assign from the same var:
foo = 1234 _dict = { "foo" : foo, "bar" : foo + 1, }
Or do it with two statements (still the same dict):
_dict = { "foo": 1234 } _dict["bar"] = _dict["foo"] + 1
If you can clarify what you are trying to achieve, there may be a more elegant solution that can be found. Often, when you need to determine the value of a dict based on another, this is because the values ββare dynamically determined using a parameterized operation. In such cases, you can sometimes use an expression for an expression / list generator. For instance.
>>> dict((v, 1234+i) for i, v in enumerate(("foo", "bar"))) {'foo': 1234, 'bar': 1235}
source share