Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

I have a lot of data that contain word "not", for example "not good". I want to convert "not good" to "notgood" (without a space).

How can I convert all of "not" in the data, erasing the space after **"not".

For example in this list

  1. i am not beautiful` --> i am notbeautiful

  2. she is not good to be a teacher --> she is notgood to be a teacher

  3. if i choose A, i think it's not bad decision ---> if i choose A, i think it's notbad decision

1 Answer

0 votes
by (41.4k points)

Here,replace not_ with not ,removing the space and you will get the desired output..

text = "I am not beautiful"

new_text = text.replace("not ", "not")

print(new_text)

output:

I am not beautiful

If you wish to learn about Python Visit this Python Course.

Browse Categories

...