0

I want to count the emojis in the text the same as I do it with the hashtags in the next function:

import emoji
def count_sent(text):
   t = re.sub('#[\w]*', 'hashtag', 'text')
   return(t.count('hashtag'))

How can I build it into this function and get this output: return(t.count('hashtag'),t.count('emoji'))

Rina
  • 27
  • 3
  • Related: https://stackoverflow.com/q/28366172/1639625 (for Java, but the regex from the question should work here, too) – tobias_k Aug 16 '22 at 09:48
  • 2
    Also, don't replace with `hashtag` and then count `hashtag`. What if that word appears in the text? Instead, just count the matches in `re.findall` or `re.finditer`. – tobias_k Aug 16 '22 at 09:49

1 Answers1

1

The emoji module that you are importing on your first line has a function emoji_count()

import emoji
print(emoji.emoji_count('text  with emoji '))
# 2
cuzi
  • 978
  • 10
  • 21