[Tutor] Iterating over a list for a certain character...
Fri, 14 Dec 2001 11:26:24 -0000
> ok, i have read a file into a list of strings, and i need to
> copy out all of the strings that contain a certain
Try the string.find() function or if its more complex the re.search()
> sort them,
You can provide your own comparison function too.
> and print them.
However there is a module designed to make this kind
of thing easier, its called:
And allows you to do:
for line in fileinput.input():
So it handles all the file opening etc. It also allows
you to process multiple files as if they were one big
one. Which might help you...
Finally you might like to read my file handling topic
on my web tutor
Author of the 'Learning to Program' web site