Discuss / Python / 就这样把

就这样把

Topic source
def normalize1(name):
    return name[0].upper() + ''.join(name[1:]).lower()


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

DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}


def str2float(s):
    def fn(x, y):
        return x * 10 + y

    def char2num(s):
        return DIGITS[s]
    return reduce(fn, map(char2num, s.replace('.', ''))) / pow(10, len(s) - s.find('.') - 1)

  • 1

Reply