Tuesday, 10 September 2013

Python Find the most frequent code

Python Find the most frequent code

I want to read a file and find the most top frequent words. Here following
is the code. I assume reading file I am making some mistake. Any
suggestion will be appreciate.
txt_file = open('result.txt', 'r')
for line in txt_file:
for word in line.strip().split():
word = word.strip(punctuation).lower()
all_words = nltk.FreqDist(word for word in word.words())
top_words = set(all_words.keys()[:300])
print top_words
Input result.txt file
Musik to shiyuki miyama opa samba japan obi Musik Musik Musik
Antiques antique 1900 s sewing pattern pictorial review size Musik 36
bust 1910 s ladies waist bust

No comments:

Post a Comment