+ 1

Filing in python

How to write a program to count the frequency of the words in a file?

3rd May 2020, 9:31 AM
Farwa Waheed
5 Answers
+ 3
Great man 👍 thanks for the missing part Literally I forgot about that 😂
3rd May 2020, 4:49 PM
Shahzaib Raza
Shahzaib Raza - avatar
+ 2
# open file in read mode file = open("example.txt", "r") # make count variable for word # which has default value 0 count = 0 # read file line by line for line in file: # read each word of each line for word in line: if word == "example": Count += 1 print ("frequency of word is: ", count) # I think you got my point....
3rd May 2020, 2:51 PM
Shahzaib Raza
Shahzaib Raza - avatar
+ 2
Yeah i gotcha. I'd try for word in line.split(): if word == 'example': count += 1
3rd May 2020, 4:43 PM
Slick
Slick - avatar
+ 2
yup i got it 🤗🤗 Thankyou Shahzaib Raza 🌸🌸 and Slick 😊
8th May 2020, 2:42 AM
Farwa Waheed
0
Have you given it a shot? Let's see the code and see what problems youre having
3rd May 2020, 9:39 AM
Slick
Slick - avatar