Discuss / Python / 交作业

交作业

Topic source

1 def normalize(name): l=name.lower() m=l.capitalize() return m a=['adam','LISA','barT'] b=list(map(normalize,a)) print b 2 from functools import reduce def fn(x,y): return xy def prod(l): return reduce(fn,l) 3 from functools import reduce dict={'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,'.':88} def char2num(m): return dict[m] def fna(x,y): return x10+y def str2float(s): a=list(map(char2num,s)) l=len(s) for i in range(l): if a[i]==88: b=i break ll=0.1*(l-b-1) c=reduce(fna,a[:b]) d=reduce(fna,a[b+1:]) return c+dll


  • 1

Reply