Skip to content

Commit

Permalink
tri python
Browse files Browse the repository at this point in the history
  • Loading branch information
davy39 committed Apr 7, 2024
1 parent 6bc81e4 commit 31625b3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
19 changes: 12 additions & 7 deletions docs/algo/tris/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,22 @@


??? python "Astuce Python : tri natif avec `sorted()` et `sort()`"
👉 En Python, vous pourrez utiliser la fonction `sorted`
=== "`help(sorted)`"
{{ IDE('scripts/help_sorted') }}

=== "`sorted(ma_liste)`"
{{ IDE('scripts/tri_hello') }}
=== "Nouvelle liste triée avec `sorted()`"
En Python, nous pouvons utiliser la fonction built-in `sorted()` pour créer une **nouvelle liste** triée.
=== "`help(sorted)`"
{{ IDE('scripts/help_sorted') }}

=== "`sorted(ma_liste, reverse = True)`"
{{ IDE('scripts/reverse') }}
=== "`sorted(ma_liste)`"
{{ IDE('scripts/tri_hello') }}

=== "`sorted(ma_liste, reverse = True)`"
{{ IDE('scripts/reverse') }}

=== "Tri "en place" avec la méthode `.sort()`"
Il est également possible d'utiliser la méthode `.sort()` des objets de type `list` pour les trier **en place**.

{{ IDE('scripts/sort_liste') }}

??? abstract "Compléments"
Pour approfondir : [Interstices](https://interstices.info/les-algorithmes-de-tri/){ .md-button target="_blank" rel="noopener" }
Expand Down
1 change: 0 additions & 1 deletion docs/algo/tris/scripts/help_sorted test.py

This file was deleted.

3 changes: 3 additions & 0 deletions docs/algo/tris/scripts/reverse_corr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
liste_1 = [1, 2, 5, 3]
print(sorted(liste_1, reverse = True))

4 changes: 4 additions & 0 deletions docs/algo/tris/scripts/sort_liste.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ma_liste=[1,5,3,8,9,2]
print(f"Ma liste avant : {ma_liste}")
ma_liste.sort(reverse=True)
print(f"Ma liste après : {ma_liste}")
4 changes: 4 additions & 0 deletions docs/algo/tris/scripts/sort_liste_corr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ma_liste=[1,5,3,8,9,2]
print(f"Ma liste avant : {ma_liste}")
ma_liste.sort(reverse=True)
print(f"Ma liste après : {ma_liste}")
5 changes: 5 additions & 0 deletions docs/algo/tris/scripts/tri_hello_corr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
liste_1 = ["Hello", "Bonjour", "Salut"]
liste_2 = sorted(liste_1)
print("liste_1 = ", liste_1)
print("liste_2 = ", liste_2)

0 comments on commit 31625b3

Please sign in to comment.