最近在学习廖雪峰的python课程,下面为学习过程中的练习题。
1、#利用map和reduce编写一个str2float函数,把字符串’123.456’转换成浮点数123.456。
使用了2种方法实现
from functools import reduce
#方法一:
DIGITS ={
'0':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6 ,'7':7, '8':8, '9':9,'.':'.'}
def str2float(s):
# 将str转换成list
s1 = list(s)
#转换成位数整数
def fn(x, y)