[Python-ideas] startsin ?

Yuval Greenfield ubershmekel at gmail.com
Fri Sep 30 17:49:41 CEST 2011


If accepted, think this could be:

1. Added as a tool in a std lib module.
2. Allow startswith/endswith to accept a tuple.
3. Added as another method to str.

I'm +1 for the first option.

Either way, there's an O(len_str + len_max_needle) algorithm for this:
http://en.m.wikipedia.org/wiki/Aho%E2%80%93Corasick_string_matching_algorithm
 On Sep 30, 2011 8: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
>
> Cheers
> Tarek
>
> --
> Tarek Ziadé | http://ziade.org
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110930/e255327e/attachment.html>


More information about the Python-ideas mailing list