Convert from numbers to letters

Jason Drew jasondrew72 at gmail.com
Thu May 19 16:38:07 EDT 2005


We weren't really backwards; just gave a full solution to a half-stated
problem.

Bill, you've forgotten the least-lines-of-code requirement :-)

Mine's still a one-liner (chopped up so line breaks don't break it):

z = lambda cp: (int(cp[min([i for \
    i in xrange(0, len(cp)) if \
    cp[i].isdigit()]):])-1,
    sum(((ord(cp[0:min([i for i in \
    xrange(0, len(cp)) if \
    cp[i].isdigit()])][x])-ord('A')+1) \
    * (26 ** (len(cp[0:min([i for i in \
    xrange(0, len(cp)) if \
    cp[i].isdigit()])])-x-1)) for x in \
    xrange(0, len(cp[0:min([i for i in \
    xrange(0, len(cp)) if \
    cp[i].isdigit()])]))))-1)

print z("B14")
# gives (13, 1)

Maybe brevity isn't the soul of wit after all ...




More information about the Python-list mailing list