
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_algorith... On Sep 30, 2011 8: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"
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@python.org http://mail.python.org/mailman/listinfo/python-ideas