init: initial commit
This commit is contained in:
+3
-3
@@ -121,8 +121,8 @@ celerybeat.pid
|
|||||||
*.sage.py
|
*.sage.py
|
||||||
|
|
||||||
# Environments
|
# Environments
|
||||||
.env
|
.env/
|
||||||
.venv
|
.venv/
|
||||||
env/
|
env/
|
||||||
venv/
|
venv/
|
||||||
ENV/
|
ENV/
|
||||||
@@ -158,5 +158,5 @@ cython_debug/
|
|||||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
# 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
|
# 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.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
.idea/
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
[project]
|
||||||
|
name = "training-cg"
|
||||||
|
version = "0.1.0"
|
||||||
|
requires-python = ">=3.12"
|
||||||
|
dependencies = []
|
||||||
+21
@@ -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()
|
||||||
Reference in New Issue
Block a user