0
How to count no of words line by line in Python?
I wrote below code - file = open("newfile.txt", "w") file.write ("" "abc abhi deh kjhkl Abh abc ahjk akls Kllls shift abc abc def" "") file.close() filename = "newfile.txt" import re count = 0 with open(filename) as f: for line in f: if "abc" in line" count += len(re.findall(r"abc", line)) print count This code is working. But when I replace file with a zipped file, it doesn't work. The only change in case of zipped would be import gzip filename =gzip.open("file-name") Pls correct me.
1 Réponse
0
Here is my version
https://code.sololearn.com/cWm4N9F4SVJ4/?ref=app