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

Guido van Rossum guido at python.org
Wed Aug 31 05:27:40 CEST 2005


On 8/30/05, Andrew Durdin <adurdin at gmail.com> wrote:
> On 8/31/05, Delaney, Timothy (Tim) <tdelaney at 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/)


More information about the Python-Dev mailing list