Exercice 82
Écrire un algorithme Python qui supprime toutes les chaînes vides d'une liste de chaînes.
Exemple: Si :
|
1 |
L = ["Python" , "" , "is" , "" , "the", "most" , "", "used" , "programming", "language" , ""] |
l'algorithme renvoie:
|
1 |
['Python', 'is', 'the', 'most', 'used', 'programming', 'language'] |
Solution
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# coding: utf-8 def remove_empty_string(L): # initialisation de la liste sans chaine vide newList = [] # parcourir les éléments de la liste L for word in L: if word != "": newList.append(word) return newList # Exemple L = ["Python" , "" , "is" , "" , "the", "most" , "", "used" , "programming", "language" , ""] print(remove_empty_str(L)) # La sortie est : # ['Python', 'is', 'the', 'most', 'used', 'programming', 'language'] |
Younes Derfoufi
CRMEF OUJDA
Acheter sur Très Facile !
-

Python pour les Nuls, 4è édition - John Paul Mueller
€ 25,00 Acheter le livre -
Promo !

TP-Link Routeur WiFi 6 Archer AX18** WiFi 6 nouvelle génération
Le prix initial était : € 40,00.€ 35,00Le prix actuel est : € 35,00. Acheter le produit -

Introduction à l'Information Quantique: Quantum Toolbox in Python
€ 64,00 Acheter le livre
1 thought on “Solution Exercice 82: algorithme python qui supprime les chaines vide d'une liste de chaine”