Pour supprimer rapidement les éléments d'une liste python contenant des strings avec uniquement des espaces il suffit par exemple d'utiliser "isspace" comme dans cet exemple:
>>> l = ['Bob',' ','Ben','Bill',' ','Peter']>>> l[0].isspace()False>>> l[1].isspace()True>>> l = [i for i in l if not i.isspace()]>>> l['Bob', 'Ben', 'Bill', 'Peter']>>>
Recherches associées
| Liens | Site |
|---|---|
| Remove empty string from list | stackoverflow |
| How to check if text is “empty” (spaces, tabs, newlines) in Python? | stackoverflow |
| Most elegant way to check if the string is empty in Python? | stackoverflow |
| Best way to check if a list is empty | stackoverflow |
