Last active
August 29, 2015 13:56
-
-
Save abdalla-alothman/9293942 to your computer and use it in GitHub Desktop.
Convert Arabic to Hindi numerals and vice versa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
class ArIdNumberHandler: | |
def __init__(self): | |
self.numMap = {0: "٠", | |
1: "١", | |
2: "٢", | |
3: "٣", | |
4: "٤", | |
5: "٥", | |
6: "٦", | |
7: "٧", | |
8: "٨", | |
9: "۹"} | |
self.valMap = {vals:ints for ints, vals in self.numMap.items()} | |
def arToHindi(self, intNum=0): | |
sNum = str(intNum) | |
result = ''.join([self.numMap[int(val)] for val in sNum]) | |
return result | |
def hindiToAr(self, strNum=str()): | |
result = ''.join([str(self.valMap[val]) for val in strNum]) | |
return int(result) | |
converted = ArIdNumberHandler().arToHindi(3) | |
print(converted) | |
converted = ArIdNumberHandler().arToHindi(1970) | |
print(converted) | |
converted = ArIdNumberHandler().hindiToAr("٦٨٥٦") | |
print(converted, " - ", type(converted)) | |
# sample output | |
#٣ | |
#١۹٧٠ | |
#6856 - <class 'int'> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment