我已经预先定义了一个字符串触发器列表:
triggers = {'academic': ['studied at', 'studies at', 'studies', 'studies at'],
'age': ['years old','months old'],
'gender': ['male', 'female'],
'pets': ['dog','cat'],
'location': ['Lived in','Lives in']}
我有一个以前不知道的分组信息数据列表,例如:
example_list_of_list = [['Former Teacher of math at'],
['Studies programming at', 'Stackoverflow'],
['Lives in','Chicago'],
['owns','dog', 'cat']
我想使用匹配预定义键值将每个匹配列表元素附加到新字典中,例如:
{'academic': ['Former Teacher of math at'],
'age': None, # np.nan or []
'gender': None, # np.nan or []
'pets': ['owns','dog','cat']
'location': ['Lives in','Chicago']
}
谢谢!你知道吗
我认为,使用集合语义最容易做到这一点:
但请注意以下几点:
triggers
应该是set
的dict
而不是list
的example_list_of_lists
应该是list
的set
result
是list
的dict
,因为可能有多个输入匹配相关问题 更多 >
编程相关推荐