ᔕ
Size: a a a
ᔕ
ЮЧ
ᔕ
️️
️️
ЮЧ
ЮЧ
S
️️
S
import re
from collections import Counter
from dataclasses import dataclass
from typing import Iterable
@dataclass(frozen=True)
class Post:
name: str
link: str
posts = [Post(...), ...]
def find(query: str, posts: Iterable[Post]) -> dict:
words = re.findall(r"\w+", query)
matching_posts = Counter()
for post in posts:
for word in words:
if not re.match(rf"\b{word}\b", post.name, re.IGNORECASE):
continue
matching_posts[post] += 1
return matching_posts.most_common()
S
ᔕ
ᔕ
️️
️️
ЮЧ
ᔕ
ᔕ
️️
S