linenums = [i for i in range(len(lines)) if lines[i].find(searchstring) >=0]
-----Original Message----- From: Joshua Ginsberg [mailto:[EMAIL PROTECTED] Sent: Friday, April 08, 2005 4:12 PM To: [EMAIL PROTECTED] 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 -- [EMAIL PROTECTED] 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 -- http://mail.python.org/mailman/listinfo/python-list