I would like to define one of the values in a dictionary to be a function of another value. For example:
a = 1
my_dict = {"A": a, "B": a * 2}
This works, because I define the variable a outside the dictionary. However, something like this:
my_dict = {"A":1, "B": my_dict["A"] * 2}
will raise an error, as my_dict hasn't yet been defined before I try to access its "A" value.
Of course, in the case above I can simply fix this by defining the dictionary values as variables outside the dictionary before constructing it, but when there are many entries this can become tedious.
Is there a way to access key-value pairs from within the same dictionary to do computations?