diff --git a/.gitignore b/.gitignore index 5d381cc..e257cb1 100644 --- a/.gitignore +++ b/.gitignore @@ -121,8 +121,8 @@ celerybeat.pid *.sage.py # Environments -.env -.venv +.env/ +.venv/ env/ venv/ ENV/ @@ -158,5 +158,5 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ +.idea/ diff --git a/lru_cache.py b/lru_cache.py new file mode 100644 index 0000000..1523ff0 --- /dev/null +++ b/lru_cache.py @@ -0,0 +1,24 @@ +class LRUCache: + + def __init__(self, capacity: int): + self.capacity = capacity + self.slots = [] + + def get(self, key: int) -> int: + if key <= len(self.slots) -1: + return self.slots[key] + return -1 + + def put(self, key: int, value: int) -> None: + if self.capacity > len(self.slots): + self.slots.append(value) + else: + self.slots[len(self.slots) - 1] = value + +def main(): + cache = LRUCache(2) + print(cache.get(1)) + print(cache.get(0)) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e2882de --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,5 @@ +[project] +name = "training-cg" +version = "0.1.0" +requires-python = ">=3.12" +dependencies = [] diff --git a/training.py b/training.py new file mode 100644 index 0000000..6cf9fda --- /dev/null +++ b/training.py @@ -0,0 +1,21 @@ +def filter_keywords(text: str, keywords: list[str]) -> list[str]: + """ + Prend un texte et une liste de mots‑clés (insensibles à la casse). + Retourne les mots du texte (sans ponctuation) qui contiennent au moins un mot‑clé. + Si un mot du texte contient plusieurs mots‑clés, il n’est listé qu’une 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() diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..da0eb8d --- /dev/null +++ b/uv.lock @@ -0,0 +1,8 @@ +version = 1 +revision = 1 +requires-python = ">=3.12" + +[[package]] +name = "training-cg" +version = "0.1.0" +source = { virtual = "." }