[Python-ideas] startsin ?
p.f.moore at gmail.com
Fri Sep 30 18:21:32 CEST 2011
On 30 September 2011 17:02, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Fri, Sep 30, 2011 at 11:30 AM, Tarek Ziadé <ziade.tarek at gmail.com> wrote:
>> 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 :
>>>> "example".startswith(('c', 'd', 'e'))
>  http://docs.python.org/library/stdtypes.html#str.startswith
The time machine strikes again :-)
More information about the Python-ideas