Vers la recherche dichotomique⚓︎
Écrire une fonction recherche_dichotomique qui prend pour argument une liste lst triée et qui recherche une valeur val dans cette liste.
Si la valeur est trouvée, l'indice de la valeur est renvoyé. Sinon, on renvoie None.
Exemple d'utilisation
<span style="color:black">🐍 Script Python</span>
>>> mylist = [2, 3, 6, 7, 11, 14, 18, 19, 24]
>>> recherche_dichotomique(mylist, 14)
5
>>> recherche_dichotomique(mylist, 2)
0
>>> recherche_dichotomique(mylist, 24)
8
>>> recherche_dichotomique(mylist, 1789)
>>>
Code à trous

| <span style="color:black">🐍 Script Python</span> | |
|---|---|
1 | |
Code à trous
| <span style="color:black">🐍 Script Python</span> | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Code à trous
| <span style="color:black">🐍 Script Python</span> | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Code à trous
| <span style="color:black">🐍 Script Python</span> | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 | |