def postag_occurences(temp): counts = {} tokens = word_tokenize(temp) length = len(tokens) pos_tagged = nltk.pos_tag(tokens) freq = FreqDist([y for (x,y) in pos_tagged]) elements = [i for i in freq.elements()] for key in tagdict.keys(): counts[key] = 0 for element in elements: counts[element] = freq[element] / length return counts