Discuss / Python / 再简单的代码也要亲手敲一遍

再简单的代码也要亲手敲一遍

Topic source

翁岚敏

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

练习1 def normalize(name): return name.capitalize() L1 = ['adam', 'LISA', 'barT'] L2 = list(map(normalize, L1)) print(L2)

练习2

from functools import reduce def prod(L): return reduce(lambda x,y:x*y,L) print(prod([1,2,3]))

练习3

from functools import reduce def str2float(s): a=s.find('.') s=s.replace('.','') return reduce(lambda x,y:x10+y,map(int,s))/10*a print('str2float(\'123.456\')=',str2float('123.456'))

发现字符串都不支持pop和remove还有append的操作


  • 1

Reply