We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f915dd0 commit 2f7e024Copy full SHA for 2f7e024
.gitignore
@@ -34,3 +34,4 @@
34
/246/README.md
35
/251/README.md
36
/252/README.md
37
+/231/README.md
231/emojis.py
@@ -0,0 +1,15 @@
1
+import re
2
+from typing import List
3
+
4
+# https://stackoverflow.com/a/43147265
5
+# just for exercise sake, real life use emoji lib
6
+IS_EMOJI = re.compile(r'[^\w\s,]')
7
8
+def get_emoji_indices(text: str) -> List[int]:
9
+ """Given a text return indices of emoji characters"""
10
+ eindices = list()
11
+ for m in re.finditer(IS_EMOJI, text):
12
+ eindices.append(m.start(0))
13
+ return eindices
14
15
+# print(get_emoji_indices('😂 ROFL that is funny 😂'))
231/test_emojis.py
@@ -0,0 +1,19 @@
+import pytest
+from emojis import get_emoji_indices
+@pytest.mark.parametrize("emojis, expected", [
+ ('We 💜 Python 🐍', [3, 12]),
+ ('We are so happy 😊😍 seeing you all coding', [16, 17]),
+ ('😂 ROFL that is funny 😂', [0, 21]),
+ ('No way 😭, that is not cool 🤔', [7, 27]),
+ ('Great job 👌 hitting that Ninja 💪 belt', [10, 31]),
+ ('Good luck with your 100 days of code 💯', [37]),
+ ('Our 🥋 ninjas are on fire 🔥', [4, 25]),
+ ('Happy Valentine 💕, buy some gifts 🎁', [16, 34]),
+ ('pytest is so cool 😎, after grasping it 🤯', [18, 39]),
16
+ ('Books can be boring 😴, better to code 💪❗', [20, 38, 39]),
17
+])
18
+def test_get_emoji_indices(emojis, expected):
19
+ assert get_emoji_indices(emojis) == expected
0 commit comments