Discuss / Python / 作业

作业

Topic source

#1

def normalize(name):

    return name.capitalize()

#2

def prod(L):

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

#3

    a=len(s)

    b=s.index(".")

    DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}

    def fn(s):

        return DIGITS[s]

    s1=reduce(lambda x,y:x*10+y,map(fn,s[:b]))

    s2=reduce(lambda x,y:x*10+y,map(fn,s[b+1:]))

    return s1+s2*(10**(b-a+1))

###第三题的解答借鉴了前排一位同学的解答方法,直观易懂,感谢。


  • 1

Reply