www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Python's partition

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
Looking through Python's string functions 
(http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed 
partition():

partition(sep)
     Split the string at the first occurrence of sep, and return a 
3-tuple containing the part before the separator, the separator itself, 
and the part after the separator. If the separator is not found, return 
a 3-tuple containing the string itself, followed by two empty strings. 
New in version 2.5.

Right now we find find and findSkip; partition would be a great 
complement, and can be implemented for all forward ranges.

One question is naming - partition() is not good for us because 
std.algorithm.partition implements Hoare's in-place partition algorithm. 
How should we call the function?


Andrei
Jan 22 2011
next sibling parent so <so so.do> writes:
On Sat, 22 Jan 2011 19:44:30 +0200, Andrei Alexandrescu  
<SeeWebsiteForEmail erdani.org> wrote:

 Looking through Python's string functions  
 (http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed  
 partition():

 partition(sep)
      Split the string at the first occurrence of sep, and return a  
 3-tuple containing the part before the separator, the separator itself,  
 and the part after the separator. If the separator is not found, return  
 a 3-tuple containing the string itself, followed by two empty strings.  
 New in version 2.5.

 Right now we find find and findSkip; partition would be a great  
 complement, and can be implemented for all forward ranges.

 One question is naming - partition() is not good for us because  
 std.algorithm.partition implements Hoare's in-place partition algorithm.  
 How should we call the function?


 Andrei

splitAt? I think "split<anything>" is much better then "partition".
Jan 22 2011
prev sibling next sibling parent Torarin <torarind gmail.com> writes:
Divide? As in dividing a pie chart.

Torarin
Jan 22 2011
prev sibling next sibling parent spir <denis.spir gmail.com> writes:
On 01/22/2011 06:44 PM, Andrei Alexandrescu wrote:
 Looking through Python's string functions
 (http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed
 partition():

 partition(sep)
 Split the string at the first occurrence of sep, and return a 3-tuple
 containing the part before the separator, the separator itself, and the
 part after the separator. If the separator is not found, return a
 3-tuple containing the string itself, followed by two empty strings. New
 in version 2.5.

 Right now we find find and findSkip; partition would be a great
 complement, and can be implemented for all forward ranges.

 One question is naming - partition() is not good for us because
 std.algorithm.partition implements Hoare's in-place partition algorithm.
 How should we call the function?

separate(d) Denis _________________ vita es estrany spir.wikidot.com
Jan 22 2011
prev sibling next sibling parent reply Christopher Nicholson-Sauls <ibisbasenji gmail.com> writes:
On 01/22/11 11:44, Andrei Alexandrescu wrote:
 Looking through Python's string functions
 (http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed
 partition():
 
 partition(sep)
     Split the string at the first occurrence of sep, and return a
 3-tuple containing the part before the separator, the separator itself,
 and the part after the separator. If the separator is not found, return
 a 3-tuple containing the string itself, followed by two empty strings.
 New in version 2.5.
 
 Right now we find find and findSkip; partition would be a great
 complement, and can be implemented for all forward ranges.
 
 One question is naming - partition() is not good for us because
 std.algorithm.partition implements Hoare's in-place partition algorithm.
 How should we call the function?
 
 
 Andrei

Bisect? -- Chris N-S
Jan 22 2011
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 1/22/11 3:33 PM, Christopher Nicholson-Sauls wrote:
 On 01/22/11 11:44, Andrei Alexandrescu wrote:
 Looking through Python's string functions
 (http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed
 partition():

 partition(sep)
      Split the string at the first occurrence of sep, and return a
 3-tuple containing the part before the separator, the separator itself,
 and the part after the separator. If the separator is not found, return
 a 3-tuple containing the string itself, followed by two empty strings.
 New in version 2.5.

 Right now we find find and findSkip; partition would be a great
 complement, and can be implemented for all forward ranges.

 One question is naming - partition() is not good for us because
 std.algorithm.partition implements Hoare's in-place partition algorithm.
 How should we call the function?


 Andrei

Bisect? -- Chris N-S

Would be rather trisect, but that becomes a bit too cute. Andrei
Jan 22 2011
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Andrei Alexandrescu:

 Would be rather trisect, but that becomes a bit too cute.

"trisect" name is acceptable :-) Bye, bearophile
Jan 22 2011
prev sibling parent Christopher Nicholson-Sauls <ibisbasenji gmail.com> writes:
On 01/22/11 15:38, Andrei Alexandrescu wrote:
 On 1/22/11 3:33 PM, Christopher Nicholson-Sauls wrote:
 On 01/22/11 11:44, Andrei Alexandrescu wrote:
 Looking through Python's string functions
 (http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed
 partition():

 partition(sep)
      Split the string at the first occurrence of sep, and return a
 3-tuple containing the part before the separator, the separator itself,
 and the part after the separator. If the separator is not found, return
 a 3-tuple containing the string itself, followed by two empty strings.
 New in version 2.5.

 Right now we find find and findSkip; partition would be a great
 complement, and can be implemented for all forward ranges.

 One question is naming - partition() is not good for us because
 std.algorithm.partition implements Hoare's in-place partition algorithm.
 How should we call the function?


 Andrei

Bisect? -- Chris N-S

Would be rather trisect, but that becomes a bit too cute. Andrei

Yeah, you're right. I hit on "bi-" because my mental image was like a binary tree search. Anywho, I actually kinda like "trisect," even if it is cute. -- Chris N-S
Jan 22 2011
prev sibling next sibling parent foobar <foo bar.com> writes:
Andrei Alexandrescu Wrote:

 Looking through Python's string functions 
 (http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed 
 partition():
 
 partition(sep)
      Split the string at the first occurrence of sep, and return a 
 3-tuple containing the part before the separator, the separator itself, 
 and the part after the separator. If the separator is not found, return 
 a 3-tuple containing the string itself, followed by two empty strings. 
 New in version 2.5.
 
 Right now we find find and findSkip; partition would be a great 
 complement, and can be implemented for all forward ranges.
 
 One question is naming - partition() is not good for us because 
 std.algorithm.partition implements Hoare's in-place partition algorithm. 
 How should we call the function?
 
 
 Andrei

sounds like JavaScript's split: string.split(separator, limit)
Jan 22 2011
prev sibling parent Tomek =?ISO-8859-2?Q?Sowi=F1ski?= <just ask.me> writes:
Andrei Alexandrescu napisa=B3:

 Looking through Python's string functions=20
 (http://docs.python.org/release/2.5.2/lib/string-methods.html) I noticed=

 partition():
=20
 partition(sep)
      Split the string at the first occurrence of sep, and return a=20
 3-tuple containing the part before the separator, the separator itself,=20
 and the part after the separator. If the separator is not found, return=20
 a 3-tuple containing the string itself, followed by two empty strings.=20
 New in version 2.5.
=20
 Right now we find find and findSkip; partition would be a great=20
 complement, and can be implemented for all forward ranges.
=20
 One question is naming - partition() is not good for us because=20
 std.algorithm.partition implements Hoare's in-place partition algorithm.=

 How should we call the function?

Instead of a one-shot function, would a lazy range of pre-hit-post troikas = be possible? That'd rhyme nicely with RegexMatch. In fact, match(string, st= ring) overload is free... --=20 Tomek
Jan 22 2011