Best way to turn word list into frequency dict

后端 未结 8 610
无人及你
无人及你 2020-12-03 17:07

What\'s the best way to convert a list/tuple into a dict where the keys are the distinct values of the list and the values are the the frequencies of those distinct values?<

8条回答
  •  误落风尘
    2020-12-03 17:31

    I find that the easiest to understand (while might not be the most efficient) way is to do:

    {i:words.count(i) for i in set(words)}
    

提交回复
热议问题