Discuss / Python / day5[中间断了好几天没学习,,ԾㅂԾ,,]

day5[中间断了好几天没学习,,ԾㅂԾ,,]

Topic source
def normalize(name):
    return name[0].upper()+name[1:].lower()


from functools import reduce

def prod(L):
    return reduce(lambda x,y:x*y,L)

from functools import reduce
def str2float(s):
    digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
    pointIndex=-1
    for i in range(0,len(s)):
        if ord(s[i]) == 46:
            pointIndex=i
            break
    if pointIndex >0:
        return reduce(lambda x,y:x*10+y,list(map(lambda z:digits[z],s[:pointIndex]+s[pointIndex+1:])))/(10**pointIndex)
    else:
        return reduce(lambda x,y:x*10+y,list(map(lambda z:digits[z],s)))


  • 1

Reply