Equivalent string.find method for a list of strings
Joshua Ginsberg
listspam at flowtheory.net
Fri Apr 8 15:42:58 EDT 2005
Try:
filter(lambda x: x.find(searchstring) != -1, lines)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Pasted Graphic.tiff
Type: image/tiff
Size: 17326 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050408/513e42dc/attachment.tiff>
-------------- next part --------------
Joshua Ginsberg -- joshg at brainstorminternet.net
Brainstorm Internet Network Operations
970-247-1442 x131
On Apr 8, 2005, at 12:17 PM, jeremit0 wrote:
> I have read a text file using the command
>
> lines = myfile.readlines()
>
> and now I want to seach those lines for a particular string. I was
> hoping there was a way to "find" that string in a similar way as
> searching simply a simple string. I want to do something like
>
> lines.find.('my particular string')
>
> Is there a module that already exists that allows me to do this or
> will I have to created my own method?
> Thanks,
> Jeremy
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list