I am learning python and i am trying to compare the values of keys in 2 dictionaries ( dict1, pickle). What i am trying to achieve here is that:
1.) the new key-value pairs of dict1 that are not available in pickle should be updated in pickle dictionary and if those values are not NULL, then those keys should be appended to updated_keys list.
2.) check if the dict1 keys already exists in pickle dictionary , check if those keys corresponding timestamp values (any change in the timestamp) are updated in pickle dictionary and whatever keys were updated in pickle dictionary should be appended to a updated_keys list.
Any help/guidance would be appreciated.
input:
dict1 = {'TOOLSTEST-2512': 'null', 'TOOLSTEST-2511': '2022-03-27T00:38:41.506-0400', 'TOOLSTEST-2510': '2022-03-28T1:38:41.506-0400', 'TOOLSTEST-2509': 'null', 'TOOLSTEST-2508': 'null'}
pickle = {'TOOLSTEST-2512': 'null', 'TOOLSTEST-2511': 'null', 'TOOLSTEST-2510': '2022-03-28T2:38:41.506-0400', 'TOOLSTEST-2509': 'null'}
Code:
updated_keys = []
for key in dict1.keys():
if ( key not in pickle.keys() and dict1[key] == 'null' ):
pickle[key] = dict1.get(key)
elif (key not in pickle.keys() and dict1[key] != 'null'):
pickle[key] = dict1.get(key)
updated_keys.append(key)
output:
updated_keys = ['TOOLSTEST-2511','TOOLSTEST-2510']