Emoji Text Replacement
Replace common English words with matching emojis to make your text more expressive.
Emoji Dictionary (sample)
love โ โค๏ธheart โ โค๏ธhappy โ ๐smile โ ๐laugh โ ๐cry โ ๐ขsad โ ๐ขangry โ ๐ cool โ ๐think โ ๐คwow โ ๐ฎfire โ ๐ฅstar โ โญsun โ โ๏ธmoon โ ๐rain โ ๐ง๏ธsnow โ โ๏ธcloud โ โ๏ธdog โ ๐cat โ ๐bird โ ๐ฆfish โ ๐horse โ ๐cow โ ๐pig โ ๐ทrabbit โ ๐ฐbear โ ๐ปlion โ ๐ฆtiger โ ๐ฏelephant โ ๐+89 more words
Pertanyaan yang Sering Diajukan
Implementasi Kode
import re
EMOJI_MAP = {
"sun": "โ๏ธ", "moon": "๐", "star": "โญ", "heart": "โค๏ธ",
"fire": "๐ฅ", "water": "๐ง", "tree": "๐ณ", "flower": "๐ธ",
"house": "๐ ", "car": "๐", "book": "๐", "music": "๐ต",
"food": "๐", "coffee": "โ", "dog": "๐ถ", "cat": "๐ฑ",
"money": "๐ฐ", "time": "โฐ", "phone": "๐ฑ", "computer": "๐ป",
"love": "๐", "happy": "๐", "sad": "๐ข", "angry": "๐ ",
"eyes": "๐", "hand": "๐", "thumbs up": "๐", "party": "๐",
"snow": "โ๏ธ", "rain": "๐ง๏ธ", "lightning": "โก", "wind": "๐ฌ๏ธ",
}
def replace_with_emojis(text: str) -> str:
"""Replace words in text with matching emojis."""
def replace_word(match):
word = match.group(0)
return EMOJI_MAP.get(word.lower(), word)
# Build pattern from longest to shortest to handle multi-word mappings
pattern = r"\b(" + "|".join(
re.escape(k) for k in sorted(EMOJI_MAP.keys(), key=len, reverse=True)
) + r")\b"
return re.sub(pattern, replace_word, text, flags=re.IGNORECASE)
text = "I love the sun, the moon, and the stars. My heart is on fire!"
result = replace_with_emojis(text)
print(result)
# Output: I โค๏ธ the โ๏ธ, the ๐, and the โญ. My โค๏ธ is on ๐ฅ!Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.