Livres
python
def text_to_str(path) -> str:
return open(path).read()
def find_str_in_str(texte, lookfor):
occurences = 0
for i in range(len(texte)):
if texte[i] == lookfor[0]:
j = 0
while j < len(lookfor) and texte[i + j] == lookfor[j] :
j += 1
if j == len(lookfor) : occurences += 1
return occurences
print(find_str_in_str(text_to_str("Notre-Dame-De-Paris.txt"), "Quasimodo"))CPES
python
def get_dict_from_csv(name: str) -> list[dict[str, str]]:
reponse = []
f = open(name)
data = f.readlines()
f.close()
lignes = data[0].split(";")
for i in range(1, len(data)):
row = data[i].split(";")
dico = {}
for j in range(len(row) - 1):
dico[lignes[j]] = row[j]
dico[lignes[len(row)-1][:-1]] = row[len(row)-1][:-1]
reponse.append(dico)
return reponse
def occurence_from_dict(data: list[dict[str, str]]):
reponse = {}
for dico in data:
if dico["Prénom"] in reponse:
reponse[dico["Prénom"]] += 1
else:
reponse[dico["Prénom"]] = 1
return reponse
def occurence_by_spé_from_dict(data: list[dict[str, str]], spé):
reponse = {}
for dico in data:
if dico["Spécialité"] == spé:
if dico["Prénom"] in reponse:
reponse[dico["Prénom"]] += 1
else:
reponse[dico["Prénom"]] = 1
return reponse
def get_name_from_very_restrcitive_spe(data: list[dict[str, str]], prénom, spé):
reponse = []
for dico in data:
if dico["Spécialité"] == spé and dico["Prénom"] == prénom:
reponse.append(dico["Nom"])
def get_name_from_very_restrcitive_group(data: list[dict[str, str]], prénom, groupe):
reponse = []
for dico in data:
if dico["Groupe"] == groupe and dico["Prénom"] == prénom:
reponse.append(dico["Nom"])
print(get_dict_from_csv("CPES1-2025-2026.csv"))