0
Write a python script to read the data from a text file India t XT find and display the occurrence of the word " India"
3 Antworten
+ 1
This might not count correctly if the word India appears more than once on a given line.   In your code, you are only counting lines with the word India, not the number of times the word India occurs.
+ 1
Jerry Hobby Thanks for pointing that out Sir. 
Himanshi Tilwani 
with open("filename.txt") as f:
         file_list = f.readlines()
         count = 0
         for line in file_list:
               line = line.split()
               for word in line:
               if word== "India":
               count+=1
 print(count)
0
Himanshi Tilwani 
with open("filename.txt") as f:
         file_list = f.readlines()
         count = 0
         for line in file_list:
               if "India" in line:
                    count +=1
         print(count)



