Skip to content

Instantly share code, notes, and snippets.

@abdalla-alothman
Last active August 29, 2015 13:56
Show Gist options
  • Save abdalla-alothman/9293942 to your computer and use it in GitHub Desktop.
Save abdalla-alothman/9293942 to your computer and use it in GitHub Desktop.
Convert Arabic to Hindi numerals and vice versa
#!/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