Discuss / Python / 作业第三题

作业第三题

Topic source

多背单词

#1 Created at ... [Delete] [Delete and Lock User]
 def char2flout(a):

    def char2num(c):
        return DIGITS[c]

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

    b = list(map(char2num, a))
    dot = b.index('')
    b.remove('')
    aaa = reduce(fn, b)
    aa = aaa / (10 ** (len(a) - dot - 1))
    return aa

多背单词

#2 Created at ... [Delete] [Delete and Lock User]

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, '.': ''}


  • 1

Reply