how to improve this simple block of code (str.partition?)

David Murmann david.murmann at rwth-aachen.de
Wed Jan 11 19:39:44 EST 2006


Peter Hansen schrieb:
> Matt's answer is still the only one that passes the tests.

well, here's another one:

-----------------------------
def mysplit(s, sep):
    x = s.rsplit(sep, 1)
    return x + ['']*(2-len(x))

def stripZeros(x):
    intpart, frac = mysplit(x, '.')
    frac = frac.rstrip('0')
    if frac:
        return intpart+'.'+frac
    else:
        return intpart
-----------------------------

i only mention this one, because i just remembered the discussion
about a str.partition method, which could save this version the
extra function. what happened to that method?

for anyone interested, it was proposed here:

  http://mail.python.org/pipermail/python-dev/2005-August/055764.html

--
David.



More information about the Python-list mailing list