Discuss / Python / str2float

str2float

Topic source

_炫Z_楚昭

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

def str2float(s): digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9} nums = s.split('.') num1 = reduce(lambda x, y: x 10 + y, map(lambda x: digits[x], nums[0])) num2 = reduce(lambda x,y: x 0.1 + y, map(lambda x: digits[x], nums[1][::-1])) return num1 + num2 * 0.1


  • 1

Reply