[Tutor] iterating in the same line

2005-08-13 Thread Jonas Melian
I would check 3 words at the starting of a line s=['foo','bar','qwe'] if ln.startswith(s): (this is bad) what is the best way for making it? if max(map(ln.startswith,s)): or reduce(lambda m,n:m or n, map(ln.startswith, s)) Thanks! ___ Tutor maillis

Re: [Tutor] iterating in the same line

2005-08-13 Thread Danny Yoo
On Sat, 13 Aug 2005, Jonas Melian wrote: > I would check 3 words at the starting of a line > > s=['foo','bar','qwe'] > > if ln.startswith(s): (this is bad) Hi Jonas, Just checking: is this similar to a question brought up a few days ago? http://mail.python.org/pipermail/tutor/2005-Augu

Re: [Tutor] iterating in the same line

2005-08-13 Thread Bob Gailer
At 12:20 PM 8/13/2005, Jonas Melian wrote: >I would check 3 words at the starting of a line > >s=['foo','bar','qwe'] > >if ln.startswith(s): (this is bad) > >what is the best way for making it? Iterations over a list of this nature are most succinctly done using list comprehensions. if [l for

Re: [Tutor] iterating in the same line

2005-08-14 Thread Alan G
Sorry Jonas, I don't understand what you are trying to do at all. The subject line and your code snippets don't seem to match up. > Subject: [Tutor] iterating in the same line >I would check 3 words at the starting of a line > > s=['foo','bar','

Re: [Tutor] iterating in the same line

2005-08-14 Thread Jonas Melian
what you are trying to do at all. > The subject line and your code snippets don't seem to match up. > >> Subject: [Tutor] iterating in the same line > > >> I would check 3 words at the starting of a line >> >> s=['foo','bar','qwe'

Re: [Tutor] iterating in the same line

2005-08-14 Thread Alan G
> I'm trying match the lines that starting with someone variable in > 's' In that case this is the simplest approach: >> for st in s: >> if line.startswith(st): do something That means that if you are reading the lines from a file you'd need a neted loop: for line in someFile: for subst