Re: Equivalent string.find method for a list of strings

2005-04-12 Thread jeremit0
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

RE: Equivalent string.find method for a list of strings

2005-04-09 Thread Sells, Fred
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(lam

Re: Equivalent string.find method for a list of strings

2005-04-08 Thread jeremit0
Steven Bethard wrote: jeremit0 wrote: Steve Holden wrote: If you want line numbers,. of course, then you can use for linenum, line in enumerate(myfile.readlines()): ... Remember that true to Python's philosophy numbering will start at zero. Is this any better than: lines = myfile.readli

Re: Equivalent string.find method for a list of strings

2005-04-08 Thread Steven Bethard
jeremit0 wrote: Steve Holden wrote: If you want line numbers,. of course, then you can use for linenum, line in enumerate(myfile.readlines()): ... Remember that true to Python's philosophy numbering will start at zero. Is this any better than: lines = myfile.readlines() for linenum

Re: Equivalent string.find method for a list of strings

2005-04-08 Thread Steve Holden
jeremit0 wrote: Steve Holden wrote: jeremit0 wrote: harold fellermann wrote: file.readlines() returns a list of lines. You can either call find on each element in this list, like: for line in myfile.readlines() : if line.find('my particular string') : do_something() I had thought that

Re: Equivalent string.find method for a list of strings

2005-04-08 Thread jeremit0
Steve Holden wrote: jeremit0 wrote: harold fellermann wrote: file.readlines() returns a list of lines. You can either call find on each element in this list, like: for line in myfile.readlines() : if line.find('my particular string') : do_something() I had thought that may be the only

Re: Equivalent string.find method for a list of strings

2005-04-08 Thread Jack Diederich
On Fri, Apr 08, 2005 at 02:17:32PM -0400, 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 si

Re: Equivalent string.find method for a list of strings

2005-04-08 Thread jeremit0
harold fellermann wrote: file.readlines() returns a list of lines. You can either call find on each element in this list, like: for line in myfile.readlines() : if line.find('my particular string') : do_something() I had thought that may be the only way to do it, I was hoping for somet

Re: Equivalent string.find method for a list of strings

2005-04-08 Thread Fredrik Lundh
"jeremit0" <[EMAIL PROTECTED]> 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

Re: Equivalent string.find method for a list of strings

2005-04-08 Thread Joshua Ginsberg
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

Re: Equivalent string.find method for a list of strings

2005-04-08 Thread Steve Holden
jeremit0 wrote: harold fellermann wrote: file.readlines() returns a list of lines. You can either call find on each element in this list, like: for line in myfile.readlines() : if line.find('my particular string') : do_something() I had thought that may be the only way to do it, I was

Re: Equivalent string.find method for a list of strings

2005-04-08 Thread Joshua Ginsberg
Try: filter(lambda x: x.find(searchstring) != -1, lines) <>Joshua Ginsberg -- [EMAIL PROTECTED] 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 l

Re: Equivalent string.find method for a list of strings

2005-04-08 Thread harold fellermann
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 stri