python - Updating tracker variables inside a dictionary -
i'm trying keep track of complex set of variables , update them, within dictionary. if dictionary not appropriate tool here, please let me know.
a = 1 b = 1 c = 1 dict = {a: [(b, c)]} # {1: [(1, 1)]} = 1 b = 1 c = 2 dict = {a: [(b, c)]} # {1: [(1, 2)]} = 1 b = 2 c = 1 dict = {a: [(b, c), (b, c)]} # {1: [(1, 2), (2, 1)]} = 2 b = 1 c = 1 dict = # {1: [(1, 2), (2, 1)], 2: [(1, 1)]} = 1 b = 1 c += 1 dict = # {1: [(1, 3), (2, 1)], 2: [(1, 1)]}
please note not viable python code, example of 4 procedures i'm trying keep track of. if changes, want new key, if b changes want new pair of values in appropriate key of a, , if c changes, want update existing pair of a: (b, c).
couple more examples given existing dictionary:
a = 2 b = 4 c = 1 dict = # {1: [(1, 3), (2, 1)], 2: [(1, 1), (4, 1)]} = 6 b = 3 c = 1 dict = # {1: [(1, 3), (2, 1)], 2: [(1, 1), (4, 1)], 6: [(3, 1)]}
my question have no idea how syntax for:
the process of updating values of c, or if possible.
adding new pairs of (b, c) existing keys without replacing existing pairs
okay, asked see i've tried.. can first 1 obviously. dict[a] = [(b, c)]
if b changes, don't know how add existing key without replacing existing pair of [(b, c)] if c changes, don't know how perform arithmetic on value inside pair inside key. sorry, i'm new, know syntax question.
any reason not use dict
of dict
s, e.g.:
>>> d = {1: {1: 1}} >>> d[1][1] = 2 >>> d {1: {1: 2}} >>> d[1][2] = 1 >>> d {1: {1: 2, 2: 1}}
Comments
Post a Comment