Discuss / Python / 有点麻烦

有点麻烦

Topic source

yan32777

#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}

    def s2n(c):

        if c!='.':

            return DIGITS[c]

        else:

            return 'dot'

    def conv(ji,n2):

        if n2!='dot':

           return ji*10+n2

        else:

            return ji

    ln=map(s2n,s)

    dgint=reduce(conv,ln)

    findpos=s.find('.')

    if findpos>=0:

        return dgint/10**(len(s)-findpos-1)

    else:

        return dgint


  • 1

Reply