I have dictionary with values as lists:
myDict = {'id1': ["name1","Type1","Value_1"],
'id2': ["name2","Type1","Value_2"],
'id3': ["name1","Type2","Value_3"],
'id4': ["name1","Type1","Value_4"]
}
I wanna iterate through dictionary and look if Name and Type pair is already in list - replace "Type 1" value by any other and resulting dictionary will be:
myDict = {'id1': ["name1","Type1","Value_1"],
'id2': ["name2","Type1","Value_2"],
'id3': ["name1","Type2","Value_3"],
'id4': ["name1","Modified_Type 1","Value_4"]
}
Have no idea currently how to deal with it with Python
It's mostly question about comparing value[0], value[1] and if both are the same in some other list - replace it.
I'm trying to iterate through existing dictionary and compare if it's values aren't in newDictionary, but obviously I'm checking if those values separately exist in newDict values not as pair:
myDict = {'id1': ["name1","Type1","Value_1"],
'id2': ["name2","Type1","Value_2"],
'id3': ["name1","Type2","Value_3"],
'id4': ["name1","Type1","Value_4"]
}
newDict = {}
for key, value in myDict.items():
if value[0] not in newDict.values() and value[1] not in newDict.values():
newDict[key] = value
else:
newDict[key] = [value[0],"Some modified value",value[2]]
print (newDict)