交作业
Topic sourcelambda x, y: x+y*0.1**len(str(y))
这句 **len(str(y))
什么意思啊,把这个去掉改成lambda x, y: x+y*0.001也可以得到结果。这样改可以吗。求解释。
没有用split的代码。。
from functools import reduce
def str2float(s):
#将'123.456'变为['1', '2', '3', '.', '4', '5', '6']
def stri(str):
L=[]
for a in str:
L.append(a)
return L
#将'123.456'变为['1', '2', '3']
def stri1(str1):
L1=[]
for b in stri(str1):
if b=='.':
break
L1.append(b)
return L1
#将'123.456'变为['4', '5', '6']
def stri2(str2):
n=-1
L2=[]
while True:
if stri(str2)[n]=='.':
break
L2.insert(n,(stri(str2)[n]))
n=n-1
return L2
#将'123.456'变为'123'
def stri3(str3):
S=''
for d in stri1(str3):
S=S+d
return S
#将'123.456'变为'456'
def stri4(str4):
S1=''
for e in stri2(str4):
S1=S1+e
return S1
#将'123.456'变为['123','456']
def stri5(str5):
L3=[]
L3.append(stri3(str5))
L3.append(stri4(str5))
return L3
#map(int,stri5(s))将['123','456']变为123与456的Iterator
return reduce(lambda x, y: x+y*0.1**len(str(y)),map(int,stri5(s)))
- 1
水蔓姐姐
学习内建函数好重要啊