[Python-ideas] startsin ?

Tarek Ziadé ziade.tarek at gmail.com
Fri Sep 30 17:30:18 CEST 2011


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"

So what about a startsin() method, that would iterate over a sequence:

if somestring.startsin('a', 'b', 'c'):
    print "yeah"

Implementing it in C should be faster as well

same deal with .endswith I guess


Tarek Ziadé | http://ziade.org

More information about the Python-ideas mailing list