forked from UTSAVS26/PySnippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext_to_emoji.py
39 lines (32 loc) · 903 Bytes
/
text_to_emoji.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
import emoji
def emoji_to_text(text):
"""Converts emojis in a text string to corresponding words.
Args:
text (str): The input text string containing emojis.
Returns:
str: The text with emojis replaced by words.
"""
emoji_dict = {
"😀": "happy",
"😢": "sad",
"😠": "angry",
"😂": "laughing",
"❤️": "love",
"🤗": "hug",
"🐱": "cat",
"👨🏻💻": "Ironman",
"🐶": "dog",
"⭐️": "star"
}
emojified_text = ""
for char in text:
if char in emoji_dict:
word = emoji_dict.get(char, char)
emojified_text += word + " "
else:
emojified_text += char + " "
return emojified_text.strip()
# Example usage:
text = "I am 😀 cuz I am a ⭐️"
converted_text = emoji_to_text(text)
print(converted_text)