Discuss / Python / 交作业

交作业

Topic source

默_kk

#1 Created at ... [Delete] [Delete and Lock User]
# -*- coding:utf-8 -*-
from functools import reduce
def normalize(name):
    return name[0].upper() + name[1:].lower()

def prod(L):
    return reduce(lambda x, y: x*y, L)

def char2num(s):
    return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s]

def str2float(s):
    x = 0
    l = s.split('.')
    x = reduce(lambda x, y: x * 10 + y, map(char2num, l[0]))
    x += reduce(lambda x, y: x * 10 + y, map(char2num, l[1]))*0.1**(len(l[1]))
    return x

  • 1

Reply