Multiplying values in a dictionary to form a new key...?

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'])

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.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.