
Sept. 30, 2011
11:03 a.m.
On Fri, Sep 30, 2011 at 6:02 PM, Nick Coghlan <ncoghlan@gmail.com> wrote:
On Fri, Sep 30, 2011 at 11:30 AM, Tarek Ziadé <ziade.tarek@gmail.com> wrote:
Hey,
not sure how people do this, or if I missed something obvious in the stdlib, but I often have this pattern:
starts = ('a', 'b', 'c') somestring = 'acapulco'
for start in starts: if somestring.startswith(start): print "yeah"
You missed something. startswith() and endswith() already accept tuples of strings to check and have done so since 2.5 [1]:
"example".startswith(('c', 'd', 'e')) True
[1] http://docs.python.org/library/stdtypes.html#str.startswith
Cheers, Nick.
Arrggggg... thanks ! :)
-- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
-- Tarek Ziadé | http://ziade.org