Equivalent string.find method for a list of strings

Joshua Ginsberg listspam at flowtheory.net
Fri Apr 8 16:11:46 EDT 2005


try:

filter(lambda x: lines[x].find(searchstring) != -1, range(len(lines)))

That will return a list with the indices of every line containing a hit 
for your search string.

-jag

-------------- 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/55e19485/attachment.tiff>
-------------- next part --------------

Joshua Ginsberg -- joshg at brainstorminternet.net
Brainstorm Internet Network Operations
970-247-1442 x131
On Apr 8, 2005, at 1:52 PM, Jeremy Conlin wrote:

> Joshua Ginsberg wrote:
>
>> Try:
>>
>> filter(lambda x: x.find(searchstring) != -1, lines)
>>
> I really like this option, but what I want to  know where in the file 
> this line exists (i.e. line 42).  Can  I somehow access this line and 
> the lines immediately following?
> Thanks,
> Jeremy
>


More information about the Python-list mailing list