I have a dict
like this:
dict = defaultdict(list, {'a': [['1', '2', 'A', 'cat'],
['1', '3', 'A', 'dog']],
'b': [['1', '2', 'A', 'cat'],
['1', '3', 'A', 'dog']],
'c': [['1', '2', 'A', 'cat'],
['2', '2', 'A', 'snake'],
['2', '2', 'A', 'bird']]}
I'd like to get all pairwise comparisons for overlapping values using the full list for each value. (Every position in the value list must match for it to be considered a match between keys)
Since a
and b
share ['1', '3', 'A', 'dog']
and c
doesn't, a/b: ['1', '3', 'A', 'dog']
.
a
, b
, c
, all share ['1', '2', 'A', 'cat']
, a/b/c: ['1', '2', 'A', 'cat']
.
Only c
has ['2', '2', 'A', 'snake']
, so c: ['2', '2', 'A', 'snake']
Preferred output is a dictionary combining the above, something like
combine_dict = {'a/b': ['1', '3', 'A', 'dog'], 'a/b/c': ['1', '2', 'A', 'cat'], 'c': [['2', '2', 'A', 'snake'], ['2', '2', 'A', 'bird']]}