[Python-Dev] partition() (was: Remove str.find in 3.0?)
Delaney, Timothy (Tim)
tdelaney at avaya.com
Tue Aug 30 03:46:37 CEST 2005
Raymond Hettinger wrote:
> Yes, there is a precise spec and yes it always returns three strings.
> Movitation and spec:
Ah - thanks. Missed that in the mass of emails.
>> My major issue is with the names - partition() doesn't sound right to
> FWIW, I am VERY happy with the name partition(). It has a long and
> delightful history in conjunction with the quicksort algorithm where
> it does something very similar to what we're doing here:
I guessed that the motivation came from quicksort. My concern is that
"partition" is not something that most users would associate with
strings. I know I certainly wouldn't (at least, not immediately). The
behaviour is obvious from the name, but I don't feel the name is obvious
from the behaviour.
If I were explaining the behaviour of partition() to someone, the words
I would use are something like:
partition() splits a string into 3 parts - the bit before the
first occurrance of the separator, the separator, and the bit
after the separator. If the separator isn't in the string at
all then the entire string is returned as "the bit before" and
the returned separator and bit after are empty strings.
I'd probably also explain that if the separator is the very last thing
in the string the "bit after" would be an empty string, but that is
fairly intuitive in any case IMO.
It's a pity split() is already taken - but then, you would want split()
to do more in any case (specifically, split multiple times).
More information about the Python-Dev