'Filter a dictionary of dictionaries by another dictionary
I have tried this answer for my problem: Match dictionary by a filter (other dictionary)
Here is the code I use :
mydict = {'foo' : 'bar', 'foo1' : {"sub_foo" : 'sub_bar', "sub_foo1" : "sub_bar1"}}
myfilter = {'foo1' : {"sub_foo" : "sub_bar"}}
setf = set(myfilter.items()) # save space
if setf == (set(mydict.items()) & setf): # if pass
print(mydict)
I get this error :
Traceback (most recent call last):
File "c:\Users\basti\Documents\IVAO and VATSIM py wrapper\python-ivao\simple_test.py", line 29, in <module>
setf = set(myfilter.items()) # save space
TypeError: unhashable type: 'dict'
I would like to have a way to tell if the filter sub_dict is included in the dict.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
