Discuss / Python / 习题3.。。。。。。。。。。。。。。。。。。

习题3.。。。。。。。。。。。。。。。。。。

Topic source
def f1(a,b):
  return a*10+b
def f2(n):
  return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[n]
t=s.find('.')
if t == -1:
  return reduce(f1,map(f2,s))
else:
  return reduce(f1,map(f2,s[:t]+s[t+1:]))/10**(len(s)-t-1)

  • 1

Reply