From 5aebf67966a35cea1e1f327335e2bf4a165ae4ef Mon Sep 17 00:00:00 2001 From: Tom Wojcik Date: Wed, 5 Jan 2022 12:57:14 +0100 Subject: [PATCH] add support for count unique --- emoji/core.py | 9 +++++++-- tests/test_core.py | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/emoji/core.py b/emoji/core.py index d9967a31..23849598 100644 --- a/emoji/core.py +++ b/emoji/core.py @@ -293,8 +293,13 @@ def distinct_emoji_lis(string, language=None): return distinct_list -def emoji_count(string): - """Returns the count of emojis in a string.""" +def emoji_count(string, unique=False): + """Returns the count of emojis in a string. + + :param unique: (optional) True if count only unique emojis + """ + if unique: + return len(distinct_emoji_lis(string)) return len(emoji_lis(string)) diff --git a/tests/test_core.py b/tests/test_core.py index b3386d16..e5bb7a10 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -256,6 +256,7 @@ def test_emoji_count(): assert emoji.emoji_count('Hi, I am fine. 😁') == 1 assert emoji.emoji_count('Hi') == 0 assert emoji.emoji_count('Hello πŸ‡«πŸ‡·πŸ‘Œ') == 2 + assert emoji.emoji_count('Hello πŸ‡΅πŸ‡±πŸΊπŸ‡΅πŸ‡±', unique=True) == 2 def test_replace_emoji():