I’m interested in comparing multiple lists, taking the difference and iterating through that.
Both are list of dicts that contain the following keys:
‘ssid’ – str, ‘bssid’ – str, ‘channel’ – int, ‘flags’ – list, ‘found’ – bool
I’ve tried:
list = list(set(networks_list).difference(missing_networks))
But I receive the error:
unhashable type 'dict'
My data structure looks like this:
list: [{'found': False, 'flags': ['WPA2-PSK-CCMP', 'WPS', 'ESS'], 'ssid': 'SOHO_BROADCAST', 'bssid': '30:46:9a:9d:11:1a', 'channel': 1}, {'found': False, 'flags': ['WPA-EAP-TKIP', 'WPA2-EAP-CCMP', 'ESS'], 'ssid': 'Cisco 2.4ghz', 'bssid': '40:f4:ec:7f:3c:5a', 'channel': 11}, {'found': False, 'flags': ['WPA-EAP-TKIP', 'WPA2-EAP-CCMP', 'ESS'], 'ssid': 'Cisco 5.0ghz', 'bssid': '40:f4:ec:7f:3c:54', 'channel': 149}]
Missing networks is initially empty.
Is there a simple way of doing this?
There are probably many pitfalls to a generic approach like this, but if your dictionaries are of mostly primitives, and not huge, you can do something like this:
Assuming your data looks something like this:
You can turn the lists of dictionaries into lists tuples (which are hashable)
Then subtract
Now you have a list of tuples
or, convert back to dictionaries
Update
I’ve changed the definition of
make_hashablebased on @gnibbler’s comment.