I've been trying to teach myself python from "How to Think Like a
Python Programmer" and have been trying to write a script that checks
'words.txt' for parameters (letters) given. The problem that is the i
can only get results for the exact sequnce of parameter 'letters'.
I'll spare posting all the different ways I've tried to search for
specific letters. But they are all generally:
for line in fin:
for linechar in line:
for ch in letters:
or the "for linechar in line:" and "for ch in letters:" get switched..
I'm getting really frustrated to say the least.
What alternative method could I use that isn't too advanced? Any
tips/suggestions on the code itself would be greatly appreciated, and
tips for learning in general.
here is the code that returns a certain sequence:
fin = open('words.txt')>>def searchtxt(letters):
words = ""
index = 0
count = 0
for line in fin:
index +=1
if letters in line.strip():
count += 1
words = line.strip() + '\n' + words
print words
print index, 'lines searched..', count, letters, 'words present'
Thank you in advance.