How to find a string in a text file, Python -
how number of times 2 characters used in text files, (e.g. ('hi')) , how print sum out int?
i tried doing this:
for line in open('test.txt'): ly = line.split() in ly: = i.count('ly') print(sum(a))
but failed, in advance!
your program fails because variable a integer , cannot apply sum function integer. several examples have been presented. here mine:
with open("test.txt") fp: = fp.read().count('ly') print(a)
Comments
Post a Comment