I feel stoopid ... this code is to verbose

Andrew Koenig ark at research.att.com
Fri Jun 14 12:50:01 EDT 2002


Max> I just cannot seem to find the nice 3-liner I expected from the
Max> beginning. Has anybody got a better solution ? I thought somebody
Max> might find it a fun exercise. Well I have...

Well, it's a little more than three lines, but how about this?

def stringSlicer(string, chunkSize = 3):
    suffix = ''
    while len(string) > chunkSize:
        suffix = '.' + string[-chunkSize:] + suffix
        string = string[:-chunkSize]
    return string + suffix

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark



More information about the Python-list mailing list