In Python, how to detect if a peace of text has a majority of ltr (left-to-right) or rtl (right-to-left) Unicode symbols?
As example someting like that:
>>> guesstextorientation("abطcdαδ")
"ltr"
>>> guesstextorientation("עִבְרִיתa")
"rtl"
It could also ignore the writing systems where the two directions are allowed like CJK.
You can use this way with
regexandUnicode escapesofrtllanguages( here I used Persian and Arabic):Code:
Output: