Equivalent string.find method for a list of strings
Sells, Fred
fred at adventistcare.org
Sat Apr 9 06:36:24 EDT 2005
linenums = [i for i in range(len(lines)) if lines[i].find(searchstring) >=0]
-----Original Message-----
From: Joshua Ginsberg [mailto:listspam at flowtheory.net]
Sent: Friday, April 08, 2005 4:12 PM
To: python-list at mail.python.org
Subject: Re: Equivalent string.find method for a list of strings
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
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
>
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list