Skip to content

Commit 2f7e024

Browse files
author
naipawat.poo@student.mahidol.ac.th
committedJan 14, 2020
bites 231
1 parent f915dd0 commit 2f7e024

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@
3434
/246/README.md
3535
/251/README.md
3636
/252/README.md
37+
/231/README.md

‎231/emojis.py

+15
Original file line numberDiff line numberDiff line change
@@ -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

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
3+
from emojis import get_emoji_indices
4+
5+
6+
@pytest.mark.parametrize("emojis, expected", [
7+
('We 💜 Python 🐍', [3, 12]),
8+
('We are so happy 😊😍 seeing you all coding', [16, 17]),
9+
('😂 ROFL that is funny 😂', [0, 21]),
10+
('No way 😭, that is not cool 🤔', [7, 27]),
11+
('Great job 👌 hitting that Ninja 💪 belt', [10, 31]),
12+
('Good luck with your 100 days of code 💯', [37]),
13+
('Our 🥋 ninjas are on fire 🔥', [4, 25]),
14+
('Happy Valentine 💕, buy some gifts 🎁', [16, 34]),
15+
('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

Comments
 (0)
Please sign in to comment.