Discuss / Python / 题目一二三解答

题目一二三解答

Topic source

-反派-

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

第一题参考: L1 = ['adam', 'LISA', 'barT']

def normalize(name): return name.capitalize() L2 = list(map(normalize,L1))

第二题参考: L1 = [3,5,7,9] from functools import reduce

def prod(x,y): return x*y product = reduce(prod,L1)

第三题参考: from functools import reduce

def str2float(s): def fn(x,y): return x*10+y n=s.index('.') s1,s2=list(map(int,s[:n])),list(map(int,s[n+1:])) #int函数可用教程中使用map()函数的方法取代 return reduce(fn,s1)+reduce(fn,s2)/(10**len(s2)) print('str2float(\'123.4567\')=',str2float('123.4567'))

lyingaloneiii

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

参考了一下 谢谢


  • 1

Reply