My assignment is requiring me to write code that can handle finding elements from one json list in another json list. Here is an example of the data:
data_to_find = {'location': {'state': 'WA'}, 'active': True}
data_to_look_in = {'id': 3, 'last': 'Black', 'first': 'Jim', 'location': {'city': 'Spokane', 'state': 'WA', 'postalCode': '99207'}, 'active': True}
print(data_to_find)
print(data_to_look_in)
output:
{'location': {'state': 'WA'}, 'active': True}
{'id': 3, 'last': 'Black', 'first': 'Jim', 'location': {'city': 'Spokane', 'state': 'WA', 'postalCode': '99207'}, 'active': True}
I have to find to find the data in data_to_find
in data_to_look_in
and I am having a lot of trouble doing this. Here is what I have tried and what it returns:
for line in data_to_find:
tmp1 = data_to_find[line]
tmp2 = data_to_look_in[line]
print(tmp1)
print(tmp2)
if tmp1 in tmp2:
print("found")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-46-cf3b325f53e8> in <module>()
4 print(tmp1)
5 print(tmp2)
----> 6 if tmp1 in tmp2:
7 print("found")
TypeError: unhashable type: 'dict'
I've tried other ways that seem to return the same error so I am looking for help on how to best approach and solve this issue. Any tips would be appreciated. Thank you. EDIT: I am trying to write this so it can be done generically not just for these specific data values.