Exercise 13
Write a Python algorithm as a function to remove duplicate elements from a list.
Solution
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
def removeDuplicate(L): # Initialize the list without duplicate elements noDuplicate = [] # Iterate through the elements of L and remove duplicates for x in L: if x not in noDuplicate: noDuplicate.append(x) return noDuplicate # Example L = [5, 19, 5, 21, 5, 13, 21, 5] print("List without duplicate elements:", removeDuplicate(L)) # Output: List without duplicate elements: [5, 19, 21, 13] |
Younes Derfoufi
CRMEF OUJDA
Acheter sur Très Facile !
-

Apprendre l'intelligence artificielle avec Python : Recherche, optimisation, apprentissage
€ 32,00 Acheter le livre -

Le langage Python pour ECG/ECT 1re et 2ème Années
€ 26,00 Acheter le livre -

Oreillette Bluetooth Sans Fil - Écouteurs Bluetooth 5.1 Contrôle Tactile, Écran LED
€ 8,00 Acheter le produit
1 thought on “Solution Exercise 13: Python algorithm to remove duplicate elements from a list”