[Python-ideas] An iterable version of find/index for strings?

Antoine Pitrou solipsis at pitrou.net
Mon Apr 8 20:14:53 CEST 2013


Hello,

On Fri, 5 Apr 2013 00:42:43 -0700
Raymond Hettinger
<raymond.hettinger at gmail.com> wrote:
> 
> On Apr 4, 2013, at 6:21 PM, Tom Schumm <phong at phong.org> wrote:
> 
> > Should Python strings (and byte arrays, and other iterables for that matter) 
> > have an iterator form of find/rfind (or index/rindex)? I've found myself 
> > wanting one on occasion, 
> 
> +1 from me.
> 
> As you say, the current pattern is awkward.  Iterators are much more
> natural for this task and would lead to cleaner, faster code.

I'm mildly positive as well.
If iterfind() / finditer() is awkward, let's call it findall(): other
search methods just return the first match.

Regards

Antoine.





More information about the Python-ideas mailing list