第一题
>>> def normalize(name):
... def t(x):
... return x.title()
... return list(map(t, name))
...
第二题
>>> from functools import reduce
>>> def prod(L):
... def mul(x, y):
... return x*y
... return reduce(mul, L)
第三题
>>> digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
>>> def str2float(s):
... return reduce(lambda x, y: x * 10 + y, map(lambda z: digits[z], s.split('.')[0])) + reduce(lambda x, y: x / 10 + y, map(lambda z: digits[z], s.split('.')[1][::-1]))/10
Sign in to make a reply
Maplin (^ω^)
第一题
>>> def normalize(name):
... def t(x):
... return x.title()
... return list(map(t, name))
...
第二题
>>> from functools import reduce
>>> def prod(L):
... def mul(x, y):
... return x*y
... return reduce(mul, L)
...
第三题
>>> digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
>>> def str2float(s):
... return reduce(lambda x, y: x * 10 + y, map(lambda z: digits[z], s.split('.')[0])) + reduce(lambda x, y: x / 10 + y, map(lambda z: digits[z], s.split('.')[1][::-1]))/10
...