Discuss / Python / 练习

练习

Topic source

fomiuna

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

一、

print(list(map(lambda x: x.title(), ['adam', 'LISA', 'barT'])))

二、

print(reduce(lambda x, y: x * y, [3, 5, 7, 9]))

三、

from functools import reduce

def str2float(s):
digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4,
          '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
power = 0
if '.' in s:
    power = len(s) - s.index('.') - 1
integers = [digits[x] for x in s if x is not '.']
return reduce(lambda x, y: x * 10 + y, integers) * 10**(- power)

print(str2float('584'))

这就像标准答案


  • 1

Reply