-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
47 lines (33 loc) · 1.06 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
minPositiveIndex prend en entrée une liste de nombres lst et
retourne le plus petit indice i tel que lst[i] est non nul.
Si i n'existe pas, la fonction retourne la longueur de la liste.
"""
def minPositiveIndex(lst: list[float]) -> int:
for i in range(len(lst)):
if lst[i] != 0:
return i
return len(lst)
"""
Permet de décaler une liste vers la droite en rajoutant des 0
shiftRight([1, 2, 3, 4], 2) -> [0, 0, 1, 2]
"""
def shiftRight(lst: list[float], k: int) -> list[float]:
temp = [0 for i in range(k)]+lst
return temp[:len(lst)]
"""
Permet de décaler une liste vers la gauche en rajoutant des nombres par la droite
shiftLeft([1, 2, 3, 4], 2, 5) -> [3, 4, 5, 5]
"""
def shiftLeft(lst: list[float], k: int, filler: float) -> list[float]:
temp = lst[k:]+[filler for i in range(k)]
return temp[:len(lst)]
"""
Permet de tester si une liste contient que des 0 ou non
isEmpty([0, 0, 0, 0]) -> True
"""
def isEmpty(lst: list[float]) -> bool:
for q in lst:
if q != 0:
return False
return True