[Python-Dev] partition() (was: Remove str.find in 3.0?)
rrr at ronadam.com
Tue Aug 30 19:09:41 CEST 2005
Raymond Hettinger wrote:
> [Delaney, Timothy (Tim)]
>>This is very useful behaviour IMO.
> Thanks. It seems to be getting +1s all around.
Wow, a lot of approvals! :)
>>Have the precise return values of partition() been defined?
+1 on the Name partition, I considered split or parts, but i agree
partition reads better and since it's not so generic as something like
get_parts, it creates a stronger identity making the code clearer.
>>IMO the most useful (and intuitive) behaviour is to return strings in
Wow, a lot of approvals! :-)
A possibly to consider:
Instead of partition() and rpartition(), have just partition with an
optional step or skip value which can be a positive or negative non zero
head, found, tail = partition(sep, [step=1])
step = -1 step would look for sep from the right.
step = 2, would look for the second sep from left.
step = -2, would look for the second sep from the right.
Default of course would be 1, find first step from the left.
This would allow creating an iterator that could iterate though a string
splitting on each sep from either the left, or right.
Weather a 0 or a |value|>len(string) causes an exception would need to
I can't think of an obvious use for a partition iterator at the moment,
maybe someone could find an example. In any case, finding the second,
or third sep is probably common enough.
More information about the Python-Dev