-3

I would like to delete words in phrases.

For example, I have this paragraph:


Do you know what would be amazingly awesome? BOS-FLL PLEASE!!!!!!! I want to fly with only you.

 I love this graphic.

 amazing customer service, again!  <3  <3  RaeAnn in SF - she's the best! #customerservice 
 Love the team running Gate E9 at LAS tonight. Waited for a delayed flight, and they kept things entertaining

 you have the absolute best team and customer service ever.  Every time I fly with you I'm delighted.  Thank you!

I got 4 phrases in a list, and I want to delete every term like "the"

I tried like it :

for i in tweets_dev:
    i.replace("the"," ")
    print(i)

but it didn't works!

I got always "the" on my list. Please guide me on what is the main error, and how I can perform above mention task. Thanks in advance.

thanks for reading

Zubad Ibrahim
  • 371
  • 2
  • 14
john
  • 9
  • 4
  • 3
    Does this answer your question? https://stackoverflow.com/questions/12723751/replacing-instances-of-a-character-in-a-string – jrmylow Sep 19 '20 at 13:39

1 Answers1

0

Try
tweets_dev.lower().replace(' the ', ' ')

Output:

 i love this graphic.

 amazing customer  service, again!  <3  <3  raeann in sf - she's best! #customerservice
 love team running gate e9 at las tonight. waited for a delayed flight, and they kept things entertaining

 you have absolute best team and customer service ever.  every time i fly with you i'm delighted.  thank you!```
Stress_
  • 390
  • 3
  • 10
  • `replace` isn't in-place, you need to assign the return value to something. Also be careful for word boundaries and casing (I don't know what OP wants here but this will do `"thesaurus"` -> `" saurus"`). – ggorlen Sep 19 '20 at 13:51
  • I've edited the answer so it respects word boundaries and casing. – Stress_ Sep 19 '20 at 14:16
  • Spaces aren't the same as word boundaries. It now fails on "`The boy"`. I'd ask OP for clarification before making these assumptions, and we still have an assignment problem--`replace` doesn't mutate the argument object. – ggorlen Sep 19 '20 at 14:21
  • As far as I could tell, he would want ` The boy` to be replaced, but if he could elaborate further that'd help people answer his question. – Stress_ Sep 19 '20 at 14:27