Discuss / Python / 第三题

第三题

Topic source

UTOO_NAIVE

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

from functools import reduce

def str2float(s): import math import re if re.match('^\d+(.\d+)?$',s) == None: print('不是float类型') return sList = str(s).split('.') res1 = reduce(lambda x, y: x * 10 + y, map(int, sList[0])) if len(sList) > 1: res2 = reduce(lambda x, y: x * 10 + y, map(int, sList[1])) return res1 + res2 * math.pow(10, -len(sList[1])) else: return reduce(lambda x, y: x * 10 + y, map(int, s))


  • 1

Reply