我正在尝试根据列表中某些单词childList
在另一个列表中的隶属度来计数motherList
childList= ['hello', 'i', 'love', 'cake', 'yay!'
motherList= ['yay!', 'love']
我的问题是两方面的:
什么数据结构可以让我记录每个单词的出现?
那我该如何计算他们的复发率?
您可以使用dict理解并list.count
创建您的反词典:
>>> {i:words.count(i) for i in positiveWords}
{'yay!': 1, 'love': 1}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句