1. Remove Emojis from a Text String
This program removes all emojis from a given text string.
import demoji
text = "Python is fun! ππ₯ Let's code! π»π"
cleaned_text = demoji.replace(text, "")
print(cleaned_text)
#source Code --> clcoding.com
Python is fun! Let's code!
2. Replace Emojis with Descriptions
This program replaces emojis in a text with their corresponding descriptions.
import demoji
text = "Good morning! ☀️ Have a nice day! πΈπ"
emojis = demoji.findall(text)
for emoji, description in emojis.items():
text = text.replace(emoji, f"[{description}]")
print(text)
#source Code --> clcoding.com
Good morning! [sun] Have a nice day! [cherry blossom][smiling face with smiling eyes]
3. Count the Number of Emojis in a Text
This program counts how many emojis are present in a text string.
import demoji
text = "Coding is awesome! π¨π»ππ€"
emoji_count = len(demoji.findall(text))
print(f"Number of emojis: {emoji_count}")
#source Code --> clcoding.com
Number of emojis: 3
4. Extract All Emojis from a Text
This program extracts all the emojis from a given text string.
import demoji
text = "Enjoy your meal! π½️πππ"
emojis = demoji.findall(text)
print("Emojis found:", list(emojis.keys()))
#source Code --> clcoding.com
Emojis found: ['π', 'π½️', 'π', 'π']
5. Create an Emoji Frequency Dictionary
This program creates a dictionary that maps each emoji in a text to the number of times it appears.
import demoji
text = "I love π and π. Do you like π too? ππ"
emoji_freq = {}
emojis = demoji.findall(text)
for emoji in emojis.keys():
emoji_freq[emoji] = text.count(emoji)
print("Emoji Frequency:", emoji_freq)
#source Code --> clcoding.com
Emoji Frequency: {'π': 1, 'π': 4}
0 Comments:
Post a Comment