Avec python il existe plusieurs possibilités pour supprimer certains caractères d'une chaine de caractères. Voici une astuce possible:
>>> s = "Bonjour, comment ca va ?. {Bien} c'est-a-dire [0,1]"
>>> list_sc = [",",".","-","?","'","[","]","(",")","{","}"]
>>> ''.join([i if i not in list_sc else ' ' for i in s ])
'Bonjour comment ca va Bien c est a dire 0 1 '
Recherches associées
Liens | Site |
---|---|
Remove specific characters from a string in python | stackoverflow |
Removing character in list of strings | stackoverflow |
Convert a list of characters into a string | stackoverflow |
Check if something is NOT in a list in Python | stackoverflow |
python one-line list comprehension: if-else variants | stackoverflow |