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
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
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
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','
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'
> 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