Ho una stringa immessa dall'utente e voglio cercarla e sostituire qualsiasi occorrenza di un elenco di parole con la mia stringa sostitutiva.Sostituisci tutte le parole dall'elenco delle parole con un'altra stringa in python
import re
prohibitedWords = ["MVGame","Kappa","DatSheffy","DansGame","BrainSlug","SwiftRage","Kreygasm","ArsonNoSexy","GingerPower","Poooound","TooSpicy"]
# word[1] contains the user entered message
themessage = str(word[1])
# would like to implement a foreach loop here but not sure how to do it in python
for themessage in prohibitedwords:
themessage = re.sub(prohibitedWords, "(I'm an idiot)", themessage)
print themessage
Il codice precedente non funziona, sono sicuro di non capire come funziona Python for loops.
Si dovrebbe cercare di verificare l'attuazione SpamBayes per Python potrebbe essere più scalabile. – dusual