Relative Frequency in Python -


is possible calculate relative frequency of elements occurring in list in python?

for example:

['apple', 'banana', 'apple', 'orange'] # apple example 0.5 

you can use nltk this:

import ntlk text = ['apple', 'banana', 'apple', 'orange'] fd = nltk.freqdist(text) 

check out tutorial in book how to , the source code

alternately, use counter:

from collections import counter text = ['apple', 'banana', 'apple', 'orange'] c = counter(text) 

Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -