I have a dictionary like so:
d = {}
d['key1'] = [('tuple1a', 'tuple1b', ['af1', 'af2', 'af3']),
('tuple2a', 'tuple2b', ['af4', 'af5', 'af6']),
('tuple3a', 'tuple3b', ['af7', 'af8', 'af9'])]
I want to write a function to allow me to update the list portion of the value (e.g. ['af1','af2','af3']
). The code below works to filter by the different values to get to the correct list within the value:
def update_dict(dictionary, key, tuple_a, tuple_b, new_list=None):
for k,v in dictionary.items():
if key in k:
for i in v:
if tuple_a in i:
if tuple_b in i:
#di.update(i[2], new_lst) #this is what I'd like to do but can't get the right syntax
return dictionary
I want to add something like di.update(i[2], new_lst)
My question is how can I update ONLY the list value with a new list?