Hi guys

Please can someone help me with this…I’m wanting to make a ‘term frequency’ program which counts the strings in a list and then gives the number of times the strings have been repeated, for example…

terms=[‘a’,‘horse’,‘a’,‘fast’,‘horse’,‘jumps’,‘over’,‘the’,‘smart’,‘duck’]

({‘a’: 2, ‘horse’: 2, ‘over’: 1, ‘fast’: 1, ‘duck’: 1, ‘the’: 1, ‘jumps’: 1, ‘smart’: 1})

However, I then need to then divide the string frequency by the amount of strings in the list…So in this case 10!

This is what I have so far, how do I divide the counts by the length of terms (number of strings in the list) to get termfrequency?

from collections import Counter

terms=[‘a’,‘horse’,‘a’,‘fast’,‘horse’,‘jumps’,‘over’,‘the’,‘smart’,‘duck’]

counts = Counter(terms)

termfrequency = counts/terms

print(counts)

Counter({})

Any replies appreciated