I haven’t had to do this before and not sure if it’s even possible. Any thoughts help would be appreciated!
Example:
import math
mydict = {
'a' : 4,
'b' : 5,
'c' : int(['mydict']['a']) * int(['mydict']['b']),
}
print(mydict['c'])
If you want to create a new property named c
, then assign the result of multiplying mydict['a'] * mydict['b']
to mydict['c']
outside the dictionary.
Unfortunately, you cannot do this in python(I believe there’s rare programming language could do this), because you’re defining a dictionary and at the same time you want to use it inside this definition, it looks like impossible.
As Randel said, you can get the value out of the dictionary as variable and multiple them, then save into dictionary as new item, this can be a better way.