在执行以下代码时,我将得到一个s=0结果:
import emojis
import emoji
from collections import Counter
#count emoji
#function to check if sth is an emoji
def char_is_emoji(character):
return character in emoji.UNICODE_EMOJI
#function to count emoji
def emoji_counter(text_string):
count = 0
for x in text_string:
a = char_is_emoji(x)
if a ==True:
count+=1
return count
#test
s = " Last clue! \nWho's the host of"
print(emoji_counter(s)) 知道为什么吗?任何帮助都非常感谢!
发布于 2021-12-07 18:25:19
在我的emoji版本(v1.6.1)中,emoji.UNICODE_EMOJI_ENGLISH工作:
import emoji
def emoji_counter(s):
return sum(c in emoji.UNICODE_EMOJI_ENGLISH for c in s)
s = " Last clue! \nWho's the host of"
print(emoji_counter(s)) # 2或者尝试emoji.UNICODE_EMOJI['en'] (https://github.com/carpedm20/emoji/issues/155):
在1.0.0版中增加了对表情符号多语言命名的支持。现在
UNICODE_EMOJI有了语言键 UNICODE_EMOJI ={ 'en':UNICODE_EMOJI_ENGLISH,'es':UNICODE_EMOJI_SPANISH,'pt':UNICODE_EMOJI_PORTUGUESE,'it':UNICODE_EMOJI_ITALIAN,}
https://stackoverflow.com/questions/70265013
复制相似问题