Skip to content

Instantly share code, notes, and snippets.

@mthri
Created February 5, 2022 07:12
Show Gist options
  • Save mthri/17d2af8c7238044dd2375ef664e9ad4f to your computer and use it in GitHub Desktop.
Save mthri/17d2af8c7238044dd2375ef664e9ad4f to your computer and use it in GitHub Desktop.
convert arabic alphabet to persian in python
def arabic_to_persian(text: str) -> str:
# arabic: persian
characters = {
'ك': 'ک',
'دِ': 'د',
'بِ': 'ب',
'زِ': 'ز',
'ذِ': 'ذ',
'شِ': 'ش',
'سِ': 'س',
'ى': 'ی',
'ي': 'ی',
'١': '۱',
'٢': '۲',
'٣': '۳',
'٤': '۴',
'٥': '۵',
'٦': '۶',
'٧': '۷',
'٨': '۸',
'٩': '۹',
'٠': '۰',
}
for arabic, persian in characters.items():
text = text.replace(arabic, persian)
return text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment