Guido van Rossum wrote:
> On 8/30/05, Andrew Durdin <[EMAIL PROTECTED]> wrote:
[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. :-)
> 
So we can check that a substring x appears precisely once in the string 
s using

s.partition(x) == s.rpartition(x)

Oops, it fails if s == "". I can usually find some way to go wrong ...

tongue-in-cheek-ly y'rs  - steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to