第一题
def normalize(name): return name.title() L1 = ['adam','LISA','barT'] L2 = list(map(normalize,L1)) print(L2)
def normalize(name): return name.title()
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('3*5*7*9 =',prod([3,5,7,9]))
第三题
from functools import reduce def char2num(s): return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s] def str2float(s): return reduce(lambda x,y : x * 10 + y,map(char2num,''.join(s.split('.'))))*(10**(s.index('.')-len(s)+1)) print('str2float(\'123.456\') = ',str2float('123.456'))
Sign in to make a reply
JKjenken
第一题
第二题
第三题