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

Andrew Barnert abarnert at yahoo.com
Mon Apr 8 08:58:09 CEST 2013


On Apr 7, 2013, at 23:43, Yuval Greenfield <ubershmekel at gmail.com> wrote:

> On Fri, Apr 5, 2013 at 12:11 PM, Wolfgang Maier <wolfgang.maier at biologie.uni-freiburg.de> wrote:
>> Tom Schumm <phong at ...> writes:
>> 
>> >
>> > Should Python strings (and byte arrays, and other iterables for that
>> > matter) have an iterator form of find/rfind (or index/rindex)?
>> 
>> +1 as well.
>> 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.

Yes, but regular expressions shouldn't be the one way to do a simple text search!

> * Strings are usually short and always entirely in memory - the iterator requirement isn't commonplace.

This, I think, is a better point. If you need iterfind, there's a good chance you're going to want to replace the string with an mmap, an iterator around read, something that generates the string on the fly, etc. There will be _some_ programs for which str.iterfind is more useful than a generic iterfind function, but maybe not that many...

> 
> Yuval
> _______________________________________________
> 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/20130407/56bd2408/attachment.html>


More information about the Python-ideas mailing list