a gift function and a question

Mohsen Pahlevanzadeh mohsen at pahlevanzadeh.org
Tue Sep 10 02:26:19 EDT 2013


I completed my two functions, i say may be poeple can use them:
######################################33         
def integerToPersian(number):
    listedPersian = ['۰','۱','۲','۳','۴','۵','۶','۷','۸','۹']
    listedEnglish = ['0','1','2','3','4','5','6','7','8','9']    
    returnList = list()
           
    for i in list(str(number)):
        returnList.append(listedPersian[listedEnglish.index(i)])

    return ''.join(returnList)

def persianToInterger(persianNumber):
    listedTmpString = list(persianNumber.decode("utf-8"))
    returnList = list()
    
    for i in listedTmpString:
        returnList.append(unicodedata.digit(i))
        
    return int (''.join(str(x) for x in returnList))
#######################################33



On Mon, 2013-09-09 at 16:20 -0400, random832 at fastmail.us wrote:
> On Mon, Sep 9, 2013, at 16:10, Mohsen Pahlevanzadeh wrote:
> > My question is , do you have reverse of this function? persianToInteger?
> 
> The int constructor is able to handle different forms of decimal
> numerals directly:
> 
> >>> int('\u06f3\u06f4\u06f5\u06f5')
> 3455





More information about the Python-list mailing list