> On string objects there is a find and rfind, a lstrip and rstrip, but > there is no rsplit function, is there a reason why there isn't, or is > this only because nobody implement it ? ( in this case I'll propose a > patch in a few days). I'm mainly using it for > 'toto.titi.tata'.rsplit('.',1) -> 'toto.titi','tata' as our internal > database representation is quite like a logical filesystem. I think the reason is that there isn't enough need for it. The special case of s.rsplit(c, 1) can be coded so easily by using rfind() that I don't see the need to add it. Our Swiss Army Knife string type is beginning to be so loaded with features that I am reluctant to add more. The cost of a new feature these days is measured in the number of books that need to be updated, not the number of lines of code needed to implement it. For your amusement only (! :-), I offer this implementation of rsplit(), which works in Python 2.3: def rsplit(string, sep, count=-1): L = [part[::-1] for part in string[::-1].split(sep[::-1], count)] L.reverse() return L --Guido van Rossum (home page: http://www.python.org/~guido/)
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