Discuss / Python / 打卡

打卡

Topic source
1.
def normalize(name):
    return name[0].upper() + name[1:].lower()
2.
def prod(L):
    return reduce( lambda x,y: x*y , L)
3.
    DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
    def char2num(s):
        return DIGITS[s]
    def str2int(s):
        n=s.index('.')
        return  ( reduce(lambda x, y: x * 10 + y, map(char2num, s[:n]))) +  reduce(lambda x, y: x*0.1  + y*0.1, map(char2num, '0'+s[n+1:][: :-1] ) )
    return str2int(s)

  • 1

Reply