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 l in s if ln.startswith(l)]: Caveat: This will test every word in s. If s is a large list it would be more efficient to break as soon as a match is found: match = False for l in s: if ln.startswith(l): match = True break The 3rd alternative is to use regular expression matching. That is beyond the scope of this thread. [snip] Bob Gailer mailto:[EMAIL PROTECTED] 303 442 2625 home 720 938 2625 cell _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor