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,
Tom Schumm <phong@...> writes:+1 as well.
>
> Should Python strings (and byte arrays, and other iterables for that
> matter) have an iterator form of find/rfind (or index/rindex)?
As you say, it's a logical thing to have, and there don't seem to be any
disadvantages to it.
Wolfgang
On Fri, Apr 5, 2013 at 12:11 PM, Wolfgang Maier <wolfgan...@biologie.uni-freiburg.de> wrote:Tom Schumm <phong@...> writes:+1 as well.
>
> Should Python strings (and byte arrays, and other iterables for that
> matter) have an iterator form of find/rfind (or index/rindex)?
As you say, it's a logical thing to have, and there don't seem to be any
disadvantages to it.
Wolfgang
I think there is a disadvantage:* It adds complexity to the str/bytes API.* These features exist in the `re` module, TSBOOWTDI.
* Strings are usually short and always entirely in memory - the iterator requirement isn't commonplace.
Yuval
On 9 Apr 2013 04:20, "Antoine Pitrou" <soli...@pitrou.net> wrote:
>
>
> Hello,
>
> On Fri, 5 Apr 2013 00:42:43 -0700
> Raymond Hettinger
> <raymond....@gmail.com> wrote:
> >
> > On Apr 4, 2013, at 6:21 PM, Tom Schumm <ph...@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.
+0 from me for findall/rfindall. The overlap keyword-only arg seems like a reasonable approach to that part of the problem, too.
Cheers,
Nick.