Spaces:
Sleeping
Sleeping
Upload code.txt
Browse files
code.txt
CHANGED
|
@@ -2183,3 +2183,44 @@ if c == 4 :
|
|
| 2183 |
else :
|
| 2184 |
print("KO")
|
| 2185 |
;;;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2183 |
else :
|
| 2184 |
print("KO")
|
| 2185 |
;;;
|
| 2186 |
+
supprimer doublon (N2)
|
| 2187 |
+
;;;
|
| 2188 |
+
Écrire une fonction supprimer_doublons qui prend en argument un tableau tab et qui renvoie un tableau contenant les mêmes éléments que la liste d'entrée, mais sans doublons.
|
| 2189 |
+
Exemples :
|
| 2190 |
+
>>> supprimer_doublons([1, 2, 2, 3, 4, 4, 5, 3, 1])
|
| 2191 |
+
[1, 2, 3, 4, 5]
|
| 2192 |
+
>>> supprimer_doublons([5, 15, 22, 5, 8, 2, 5, 2, 1])
|
| 2193 |
+
[5, 15, 22, 8, 2, 1]
|
| 2194 |
+
>>> supprimer_doublons([1, 1, 1, 1, 1])
|
| 2195 |
+
[1]
|
| 2196 |
+
>>> supprimer_doublons([])
|
| 2197 |
+
[]
|
| 2198 |
+
;;;
|
| 2199 |
+
c = 0
|
| 2200 |
+
if supprimer_doublons([1, 2, 2, 3, 4, 4, 5, 3, 1]) == [1, 2, 3, 4, 5]:
|
| 2201 |
+
print("Test 1 : OK")
|
| 2202 |
+
c += 1
|
| 2203 |
+
else :
|
| 2204 |
+
print("Test 1 : échec")
|
| 2205 |
+
if supprimer_doublons([5, 15, 22, 5, 8, 2, 5, 2, 1]) == [5, 15, 22, 8, 2, 1]:
|
| 2206 |
+
print("Test 2 : OK")
|
| 2207 |
+
c += 1
|
| 2208 |
+
else :
|
| 2209 |
+
print("Test 2 : échec")
|
| 2210 |
+
if supprimer_doublons([1, 1, 1, 1, 1]) == [1]:
|
| 2211 |
+
print("Test 3 : OK")
|
| 2212 |
+
c += 1
|
| 2213 |
+
else :
|
| 2214 |
+
print("Test 3 : échec")
|
| 2215 |
+
if supprimer_doublons([]) == []:
|
| 2216 |
+
print("Test 4 : OK")
|
| 2217 |
+
c += 1
|
| 2218 |
+
else :
|
| 2219 |
+
print("Test 4 : échec")
|
| 2220 |
+
if c == 4 :
|
| 2221 |
+
print("OK")
|
| 2222 |
+
else :
|
| 2223 |
+
print("KO")
|
| 2224 |
+
;;;
|
| 2225 |
+
|
| 2226 |
+
|