Skip to content

Commit 530c9dd

Browse files
committed
find common tags
Signed-off-by: Saurabh Misra <[email protected]>
1 parent 6696f07 commit 530c9dd

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

codeflash/result/common_tags.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from __future__ import annotations
2+
3+
4+
def find_common_tags(articles: list[dict[str, list[str]]]) -> set[str]:
5+
if not articles:
6+
return set()
7+
8+
common_tags = articles[0].get("tags", [])
9+
for article in articles[1:]:
10+
common_tags = [tag for tag in common_tags if tag in article.get("tags", [])]
11+
return set(common_tags)

tests/test_common_tags.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from codeflash.result.common_tags import find_common_tags
2+
3+
4+
def test_common_tags_1() -> None:
5+
articles_1 = [
6+
{"title": "Article 1", "tags": ["Python", "AI", "ML"]},
7+
{"title": "Article 2", "tags": ["Python", "Data Science", "AI"]},
8+
{"title": "Article 3", "tags": ["Python", "AI", "Big Data"]},
9+
]
10+
11+
expected = {"Python", "AI"}
12+
13+
assert find_common_tags(articles_1) == expected
14+
15+
articles_2 = [
16+
{"title": "Article 1", "tags": ["Python", "AI", "ML"]},
17+
{"title": "Article 2", "tags": ["Python", "Data Science", "AI"]},
18+
{"title": "Article 3", "tags": ["Python", "AI", "Big Data"]},
19+
{"title": "Article 4", "tags": ["Python", "AI", "ML"]},
20+
]
21+
22+
assert find_common_tags(articles_2) == expected

0 commit comments

Comments
 (0)