练习1 def normalize(name): return name.capitalize() L1 = ['adam', 'LISA', 'barT'] L2 = list(map(normalize, L1)) print(L2)
from functools import reduce def prod(L): return reduce(lambda x,y:x*y,L) print(prod([1,2,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的操作
Sign in to make a reply
翁岚敏
练习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的操作