• 🌙 Community Spirit

    Ramadan Mubarak! To honor this month, Crax has paused NSFW categories. Wishing you peace and growth!

Python script that can reverse Arabic text (1 Viewer)

Currently reading:
 Python script that can reverse Arabic text (1 Viewer)

Recently searched:

Engfree

Member
LV
0
Joined
Aug 20, 2023
Threads
10
Likes
0
Awards
2
Credits
819©
Cash
0$
Code:
def reverse_arabic_text(text):
    """
    Reverses Arabic text while preserving the order of letters and words.
    
    Args:
        text (str): The Arabic text to be reversed.
        
    Returns:
        str: The reversed Arabic text.
    """
    reversed_text = ""
    words = text.split()
    
    for word in words:
        reversed_word = ""
        for char in word:
            if '\u0600' <= char <= '\u06FF':  # Check if the character is Arabic
                reversed_word = char + reversed_word
            else:
                reversed_word += char
        reversed_text = reversed_word + " " + reversed_text
    
    return reversed_text.strip()

# Usage example
arabic_text = "مرحبا بكم في عالم البرمجة"
reversed_arabic = reverse_arabic_text(arabic_text)
print(reversed_arabic)
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Tips
Recently searched:

Similar threads

Users who are viewing this thread

Top Bottom