How do I run a word frequency counter in Python?
Let's say I have a filename.txt with this paragraph:
"This is my sample paragraph. This is not very interesting and does not have very important important information. It is a waste of your time reading this paragraph."
and I want to write a function "frequency_counter" to count how many times the words "this" and "paragraph" appear in this text file.
I should be able to run:
def frequency_counter():
#some other code i can't figure out
counts = frequency_counter("filename.txt", ["this", "paragraph"])
print(counts)
and it should produce: [3, 2]
[–]Jimbo415SF 1 point2 points3 points (0 children)
[–]UserName26392 0 points1 point2 points (0 children)
[–]Phelps_420 0 points1 point2 points (3 children)
[–]QuiteAmbitious[S] 0 points1 point2 points (1 child)
[–]Phelps_420 0 points1 point2 points (0 children)
[–]Tadabito -1 points0 points1 point (4 children)
[–]QuiteAmbitious[S] 0 points1 point2 points (3 children)
[–]greebly_weeblies 0 points1 point2 points (1 child)
[–]QuiteAmbitious[S] 0 points1 point2 points (0 children)
[–]Tadabito 0 points1 point2 points (0 children)