Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions codeflash/result/common_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import annotations


def find_common_tags(articles: list[dict[str, list[str]]]) -> set[str]:
if not articles:
return set()

common_tags = set(articles[0].get("tags", []))
for article in articles[1:]:
common_tags.intersection_update(article.get("tags", []))
if not common_tags:
break
return common_tags
22 changes: 22 additions & 0 deletions tests/test_common_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from codeflash.result.common_tags import find_common_tags


def test_common_tags_1() -> None:
articles_1 = [
{"title": "Article 1", "tags": ["Python", "AI", "ML"]},
{"title": "Article 2", "tags": ["Python", "Data Science", "AI"]},
{"title": "Article 3", "tags": ["Python", "AI", "Big Data"]},
]

expected = {"Python", "AI"}

assert find_common_tags(articles_1) == expected

articles_2 = [
{"title": "Article 1", "tags": ["Python", "AI", "ML"]},
{"title": "Article 2", "tags": ["Python", "Data Science", "AI"]},
{"title": "Article 3", "tags": ["Python", "AI", "Big Data"]},
{"title": "Article 4", "tags": ["Python", "AI", "ML"]},
]

assert find_common_tags(articles_2) == expected
Loading