Python - How to iterate/loop character by character over text


filename = input("Enter a filename: ")
with open(filename) as f:
text = f.read()
# look for char r in the input file
char=r

count = 0
for c in text:
if c == char:
count += 1

Comments

Popular posts from this blog

Python - Argument Passing

Python - How to Escape special characters in String