Files
training-cg/training.py
T
2026-06-12 20:40:30 +02:00

22 lines
678 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
def filter_keywords(text: str, keywords: list[str]) -> list[str]:
"""
Prend un texte et une liste de motsclés (insensibles à la casse).
Retourne les mots du texte (sans ponctuation) qui contiennent au moins un motclé.
Si un mot du texte contient plusieurs motsclés, il nest listé quune fois.
"""
res = []
for word in keywords:
nb_occ = text.lower().count(word.lower())
res.extend([word] * nb_occ)
return res
def main():
text = "Python est génial ! J'adore Python, surtout les listes."
keywords = ["python", "liste"]
print(filter_keywords(text, keywords))
if __name__ == "__main__":
main()