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

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -