this is one of my exercises in Python ebook. I just wonder if it is possible to use WHILE instead of FOR. Thanks for your help
#Ask the user to enter a regular expression #count the number of lines that matched the regular expression.
My code
x= input('Enter a regular expression.')
file = open('mbox-short.txt')
count = 0
for line in file: line=line.rstrip()
if re.search('\\b' + x + '\\b', line):
count=count+1
print (count)