Discuss / Python / practice

practice

Topic source

第一题:

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

第二题:

def prod(x,y):    return x * y

第三题:

def str2float(str):    def fn(x,y):        return 10 * x + y    def char2int(x):        digits = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}        return digits[x]    index = str.index('.')    s1 = list(map(int,(t for t in str[:index])))    s2 = list(map(int,(t for t in str[index+1:])))    return reduce(fn,s1) + reduce(fn,s2)/10**len(s2)

  • 1

Reply