tegge-classroom / STAT2984-2018

STAT 2984: Statistical Programming I - Spring 2018
1 stars 13 forks source link

How do you count the frequency of a key? #12

Open abbyt99 opened 6 years ago

abbyt99 commented 6 years ago

I was wondering what the easiest way to count the frequency of a key in a dictionary is.

mbecker3 commented 6 years ago

I'm not sure if this is the easiest way to do it, but here is a relatively simple method for counting the frequency of a key in a dictionary:

def wordListToFreqDict(wordlist): wordfreq = [wordlist.count(p) for p in wordlist] return dict(zip(wordlist,wordfreq))