[Greg Ewing]
>> Although Tim pointed out that replace() only regards
>> n+1 empty strings as existing in a string of lenth
>> n. So for consistency, find() should only find them
>> in those places, too.

[Guido]
> And "abc".count("") should return 4.

And it does, but too much context was missing in Greg's reply to make
sense of his comment.  In context Greg was seeming to say that

    "abc".count("", 100)

should return 0, and

    "abc".find("", 100)

should return -1, since "the only" empty substrings of "abc" are at
slices 0:0, 1:1, 2:2 and 3:3.  In fact we have

>>> "abc".count("", 100)
1
>>> u"abc".count("", 100)
1
>>> "abc".find("", 100)
100
>>> u"abc".find("", 100)
100

today, although the idea that find() can return an index that doesn't
exist in the string is particularly jarring.  Since we also have:

>>> "abc".rfind("", 100)
3
>>> u"abc".rfind("", 100)
3

it's twice as jarring that "searching from the right" finds the target
at a _smaller_ index than "searching from the left".
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to