[Python-ideas] startsin ?

David Stanek dstanek at dstanek.com
Fri Sep 30 17:46:38 CEST 2011

On Fri, Sep 30, 2011 at 11:30 AM, Tarek Ziadé <ziade.tarek at 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"
> 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

I tend to do something like this a lot;

  any(somestring.startswith(x) for x in starts)

Probably enough that having a method would be nice.

blog: http://www.traceback.org
twitter: http://twitter.com/dstanek
www: http://dstanek.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110930/1d021343/attachment.html>

More information about the Python-ideas mailing list