Discuss / Python / 第三题,以代码压缩到最少为目标 ^_^

第三题,以代码压缩到最少为目标 ^_^

Topic source

嗨养车

#1 Created at ... [Delete] [Delete and Lock User]

在做倒叙的时候,可能会牺牲掉一些性能。

    DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
    f = reduce(lambda x,y: x/10+y,map(lambda x: DIGITS[x],[x for x in s[::-1] if x!='.']))/10
    return f *(10**(len(s)-s.find('.')-1))

  • 1

Reply