learning with python question (HtTLaPP)

Eric Wertman ewertman at gmail.com
Sat Apr 26 16:20:23 EDT 2008


>  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 sequence of parameter 'letters'.

The "re" module comes to mind:

text = open('words.txt','r').read()
letters = 'sequence'
results = re.findall(letters,text)

result_count = len(results)

# one word per line:
for result in results :
    print result

# one line
print ' '.join(results)

of course, you may need to invest a little time in regular expression
syntax to get exactly what you want, but I think you'll find that's
not wasted effort, as this is pretty standard and used in a lot of
other places.



More information about the Python-list mailing list