我有以下字典:
s_final = {
a:[noun,adj,noun,noun,noun],
b:[verb,verb,verb,noun]
}
我想检索最重复的键值,以便我的最终输出如下:
s_final={a:[noun], b:[verb]}
答案 0 :(得分:3)
使用Counter。
>>> from collections import Counter
>>> s_final={'a':['noun','adj','noun','noun','noun'],'b':['verb','verb','verb','noun']}
>>> {i:[Counter(j).most_common(1)[0][0]] for i,j in s_final.items()}
{'a': ['noun'], 'b': ['verb']}