python漢字数字からアラビア数字へ

7379 ワード

 1 dictnum ={' ':0,' ':1,' ':2,' ':3,' ':4,' ':5,' ':6,' ':7,' ':8,' ':9,' ':10,' ':12,' ':13,' ':14,' ':18,' ':2,

 2           ' ':1,' ':2,' ':3,' ':4,' ':5,' ':6,' ':7,' ':8,' ':9,' ':10,' ':12}

 3 def getResultForDigit(a):

 4     count = len(a)-1

 5     result = 0

 6     tmp = 0

 7 

 8     while count >= 0:

 9         tmpChr = a[count:count+1]

10         tmpNum = 0

11         if tmpChr.isdigit():#              

12             tmpNum=int(tmpChr)

13         else:

14             tmpNum = dictnum[tmpChr]

15         if tmpNum >10:#  0   

16             tmp=tmpNum-10

17         #      

18         else:

19             if tmp == 0:

20                 result+=tmpNum

21             else:

22                 result+=pow(10,tmp)*tmpNum

23             tmp = tmp+1

24         count = count - 1

25     return result