假设我有两个词典列表:
v = [{'call 1': 'debit card'},
{'call 2': 'debit card'},
{'call 3': 'payment limit'},
{'call 1': 'bond'},
{'call 2': 'mortgage'},
{'call 3': 'debit card'},
{'call 1': nan},
{'call 2': 'spending limit'},
{'call 3': nan}]
和
w = [{'cluster 1': 'payment limit'},
{'cluster 2': 'debit card'},
{'cluster 3': 'bond'},
{'cluster 1': 'spending limit'},
{'cluster 2': 'debit card'},
{'cluster 3': 'mortgage'},
{'cluster 1': None},
{'cluster 2': 'debit card'},
{'cluster 3': None}]
I want to drop the null values on both 和 merge the two lists on values of the dictionaries, such that I get:
# desired outcome
[{'call 3':{'cluster 1': 'payment limit'}},
{'call 1':{'cluster 2': 'debit card'}},
{'call 1':{'cluster 3': 'bond'}},
{'call 2':{'cluster 1': 'spending limit'}},
{'call 2':{'cluster 2': 'debit card'}},
{'call 3':{'cluster 2': 'debit card'}}]
The puzzling part here to me is how to assign the calls to each cluster. As you can see debit card
appears in call 1
, call 2
和 call 3
, so in general I should be able to assign a distinct key to each cluster.