Discuss / Python / str2float

str2float

Topic source

Dokuroo

#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}
l=s.index('.') s=s[:l]+s[l+1:]
return reduce(lambda x,y:x10+y,map(lambda s:DIGITS[s],s))/(10*(len(s[l+1:len(s)])+1))


  • 1

Reply