Discuss / Python / 作业3

作业3

Topic source

s凡s

#1 Created at ... [Delete] [Delete and Lock User]
def str2float(s):
    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]
    s1,s2 = s.split(".");
    return reduce(lambda x,y : x*10+y, map(char2num, s1+s2)) / (10**len(s2))

s凡s

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

作业1:

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

作业2:

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

  • 1

Reply