Discuss / Python / 3

frantumaglia

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

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

    n =0

    for i in s:

        if i == '.':

            break

        if i!='.':

            n = n+1

    m=s[0:n]+s[n+1:]

    def fn(x, y):

        return x * 10 + y

    def char2num(s):

        return DIGITS[s]

    return reduce(fn, map(char2num, m))/10**(len(s)-n-1)


  • 1

Reply