Discuss / Python / 第三题

第三题

Topic source

Nobita

#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, '.' : 0}
    def char2num(c):
        return DIGITS[c]

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

    def cal_right_after_dot(x, y):
        return x / 10 + y

    ll = s[0 : s.index('.')]
    ll = list(map(char2num, ll))
    lr = s[-1 : s.index('.') - 1 : -1]
    lr = list(map(char2num, lr))
    left = reduce(cal_left_before_dot, ll)
    right = reduce(cal_right_after_dot, lr)
    return left + right
 lr = s[-1 : s.index('.') - 1 : -1]

请问这句是什么意思呀,大概流程我能懂是什么意思,就是这个s[::-1]最后一个-1是什么意思呢

xlhere

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

逆序


  • 1

Reply