Discuss / Python / 练习

练习

Topic source

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

第一题:

def normalize(name):

    return name.title()

第二题:

from functools import reduce

def prod(L):

     def fn(x,y):

          return x*y

     return reduce(fn,L)

第三题:

dict={'1':1,'2':2,'3':3,'4':4,'5':5,'6':6}

def str2float(s):

     def fn(x,y):

        return x*10+y

     def char2num(s):

        return dict[s]

     return reduce(fn,map(char2num,s[0:3]))+reduce(fn,map(char2num,s[4:]))*10**-3


  • 1

Reply