Re: [Python-Dev] Remove str.find in 3.0?

Andrew Durdin wrote:
Just to put my spoke in the wheel, I find the difference in the ordering of return values for partition() and rpartition() confusing:
head, sep, remainder = partition(s) remainder, sep, head = rpartition(s)
This is the confusion - you've got the terminology wrong. before, sep, after = s.partition('?') ('http://www.python.org', '', '') before, sep, after = s.rpartition('?') ('', '', 'http://www.python.org') Tim Delaney

On 8/31/05, Delaney, Timothy (Tim) <tdelaney@avaya.com> wrote:
Andrew Durdin wrote:
Just to put my spoke in the wheel, I find the difference in the ordering of return values for partition() and rpartition() confusing:
head, sep, remainder = partition(s) remainder, sep, head = rpartition(s)
This is the confusion - you've got the terminology wrong.
before, sep, after = s.partition('?') ('http://www.python.org', '', '')
before, sep, after = s.rpartition('?') ('', '', 'http://www.python.org')
That's still confusing (to me), though -- when the string is being processed, what comes before the separator is the stuff at the end of the string, and what comes after is the bit at the beginning of the string. It's not the terminology that's confusing me, though I find it hard to describe exactly what is. Maybe it's just me -- does anyone else have the same confusion?

On 8/30/05, Andrew Durdin <adurdin@gmail.com> wrote:
On 8/31/05, Delaney, Timothy (Tim) <tdelaney@avaya.com> wrote:
Andrew Durdin wrote:
Just to put my spoke in the wheel, I find the difference in the ordering of return values for partition() and rpartition() confusing:
head, sep, remainder = partition(s) remainder, sep, head = rpartition(s)
This is the confusion - you've got the terminology wrong.
before, sep, after = s.partition('?') ('http://www.python.org', '', '')
before, sep, after = s.rpartition('?') ('', '', 'http://www.python.org')
That's still confusing (to me), though -- when the string is being processed, what comes before the separator is the stuff at the end of the string, and what comes after is the bit at the beginning of the string. It's not the terminology that's confusing me, though I find it hard to describe exactly what is. Maybe it's just me -- does anyone else have the same confusion?
Hm. The example is poorly chosen because it's an end case. The invariant for both is (I'd hope!) "".join(s.partition()) == s == "".join(s.rpartition()) Thus, "a/b/c".partition("/") returns ("a", "/", "b/c") "a/b/c".rpartition("/") returns ("a/b", "/", "c") That can't be confusing can it? (Just think of it as rpartition() stopping at the last occurrence, rather than searching from the right. :-) -- --Guido van Rossum (home page: http://www.python.org/~guido/)

On 8/31/05, Guido van Rossum <guido@python.org> wrote:
Hm. The example is poorly chosen because it's an end case. The invariant for both is (I'd hope!)
"".join(s.partition()) == s == "".join(s.rpartition())
<snip>
(Just think of it as rpartition() stopping at the last occurrence, rather than searching from the right. :-)
Ah, that makes a difference. I could see that there was a different way of looking at the function, I just couldn't see what it was... Now I understand the way it's been done. Cheers, Andrew.

Guido van Rossum wrote:
On 8/30/05, Andrew Durdin <adurdin@gmail.com> wrote: [confusion]
Hm. The example is poorly chosen because it's an end case. The invariant for both is (I'd hope!)
"".join(s.partition()) == s == "".join(s.rpartition())
Thus,
"a/b/c".partition("/") returns ("a", "/", "b/c")
"a/b/c".rpartition("/") returns ("a/b", "/", "c")
That can't be confusing can it?
(Just think of it as rpartition() stopping at the last occurrence, rather than searching from the right. :-)
So we can check that a substring x appears precisely once in the string s using s.partition(x) == s.rpartition(x) Oops, it fails if s == "". I can usually find some way to go wrong ... tongue-in-cheek-ly y'rs - steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/

Steve Holden <steve@holdenweb.com> wrote:
Guido van Rossum wrote:
On 8/30/05, Andrew Durdin <adurdin@gmail.com> wrote: [confusion]
Hm. The example is poorly chosen because it's an end case. The invariant for both is (I'd hope!)
"".join(s.partition()) == s == "".join(s.rpartition())
Thus,
"a/b/c".partition("/") returns ("a", "/", "b/c")
"a/b/c".rpartition("/") returns ("a/b", "/", "c")
That can't be confusing can it?
(Just think of it as rpartition() stopping at the last occurrence, rather than searching from the right. :-)
So we can check that a substring x appears precisely once in the string s using
s.partition(x) == s.rpartition(x)
Oops, it fails if s == "". I can usually find some way to go wrong ...
There was an example in the standard library that used "s.find(y) == s.rfind(y)" as a test for zero or 1 instances of the searched for item. Generally though, s.count(x)==1 is a better test. - Josiah

"Delaney, Timothy (Tim)" <tdelaney@avaya.com> wrote in message
before, sep, after = s.partition('?') ('http://www.python.org', '', '')
before, sep, after = s.rpartition('?') ('', '', 'http://www.python.org')
I can also see this as left, sep, right, with the sep not found case putting all in left or right depending on whether one scanned to the right or left. In other words, when the scanner runs out of chars to scan, everything is 'behind' the scan, where 'behind' depends on the direction of scanning. That seems nicely symmetric. Terry J. Reedy
participants (6)
-
Andrew Durdin
-
Delaney, Timothy (Tim)
-
Guido van Rossum
-
Josiah Carlson
-
Steve Holden
-
Terry Reedy