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 - Recursion

Python - Sets

Python - Control Structure