Answers for "getting frequency of words in file"

1

count the frequency of words in a file

from collections import Counter
def word_count(fname):
        with open(fname) as f:
                return Counter(f.read().split())

print("Number of words in the file :",word_count("test.txt"))
Posted by: Guest on December-03-2020
0

Word frequency list (Index) for a file

% (tr ' ' 'n' | sort | uniq -c | awk '{print $2"@"$1}') <<EOF
This is a file with many words.
Some of the words appear more than once.
Some of the words only appear one time.
EOF

a@1
appear@2
file@1
is@1
many@1
more@1
of@2
once.@1
one@1
only@1
Some@2
than@1
the@2
This@1
time.@1
with@1
words@2
words.@1
Posted by: Guest on April-25-2021

Code answers related to "getting frequency of words in file"

Python Answers by Framework

Browse Popular Code Answers by Language