Phillip J. Eby wrote:
At 02:25 PM 8/30/2005 -0400, Raymond Hettinger wrote:
That case should be handled with consecutive partitions:
# keep everything after the second 'X' head, found, s = s.partition('X') head, found, s = s.partition('x')
I was thinking of cases where head is everything before the second 'X'. A posible use case might be getting items in comma delimited string.
Or:
s=s.partition('X')[2].partition('X')[2]
which actually suggests a shorter, clearer way to do it:
s = s.after('X').after('X')
And the corresponding 'before' method, of course, such that if sep in s:
s.before(sep), sep, s.after(sep) == s.partition(sep)
Technically, these should probably be before_first and after_first, with the corresponding before_last and after_last corresponding to rpartition.
Do you really think these are easer than: head, found, tail = s.partition('X',2) I don't feel there is a need to avoid numbers entirely. In this case I think it's the better way to find the n'th seperator and since it's an optional value I feel it doesn't add a lot of complication. Anyway... It's just a suggestion. Cheers, Ron