A
A
Andrew2021-12-03 01:26:27
Python
Andrew, 2021-12-03 01:26:27

What alternative to replace is there in python?

I have a list of "bad" words that need to be excluded (or replaced) from another list of texts. I would like to have something like this: it is clear that such a construction is unacceptable, what is the best way to solve such a problem, are there any alternative methods?
str.replace([list], '')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolay Savelyev, 2021-12-03
@AgentSmith

It is a bad idea.
This approach will cut out normal words like "insure", "insure", "jiggle", "rake out", etc.

G
galaxy, 2021-12-03
@galaxy

Well, what's the problem with writing a cycle of a couple of lines?

for word in words:
  s = s.replace(word, '')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question