-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChNumber.py
42 lines (38 loc) · 1020 Bytes
/
ChNumber.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
# -*- coding: utf-8-*-
## Python module that formats Persian number to Latin
## Github: https://github.com/Kourva/ChNumber
# Standard library imports
from typing import Dict
class ChNumber:
"""
:: Converts Farsi numbers to Latin"
"""
def format(number: str) -> str:
"""
:: format method:
-> Usage:
ChNumber.format(number)
-> Example:
ChNumber.format("۰۹۱۴۶۵۷۹۸۱۴")
-> Result:
"09146579814"
"""
# Pair of numbers
data: Dict = {
"۱": "1",
"۲": "2",
"۳": "3",
"۴": "4",
"۵": "5",
"۶": "6",
"۷": "7",
"۸": "8",
"۹": "9",
"۰": "0",
}
temp: str = number
for digit in temp:
if digit in data:
temp = temp.replace(digit, data[digit])
return temp