Help with String Manipulation

Greg Ewing greg.ewing at compaq.com
Thu Jun 24 05:35:16 CEST 1999


Or, if you'd like something a bit more creative:

def gnirts(s):
    n = len(s)
    if n < 2:
        return s
    else:
        return gnirts(s[n/2:]) + gnirts(s[:n/2])

print gnirts("a")
print gnirts("ab")
print gnirts("abc")
print gnirts("abcd")
print gnirts("It's not dead, it's just... resting!")

(Hmmm... the output from that last test case looks
a bit like Klingon...)

Greg




More information about the Python-list mailing list