A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-August/055837.html below:

[Python-Dev] partition() (was: Remove str.find in 3.0?)

[Python-Dev] partition() (was: Remove str.find in 3.0?)Ron Adam rrr at ronadam.com
Tue Aug 30 19:09:41 CEST 2005
Raymond Hettinger wrote:
> [Delaney, Timothy (Tim)]
> 
>>+1
>>
>>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
>>all cases.

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 
integer.

    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 
be decided.

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.


Cheers,
Ron






More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4