[Tutor] iterating in the same line
Alan G
alan.gauld at freenet.co.uk
Sun Aug 14 11:16:24 CEST 2005
> 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 substring in s:
if line.startswith(substring):
# do something here
Alternatively a regular exression match as suggested by others is
probably
faster.
Alan G.
More information about the Tutor
mailing list