Finding a sub string and deleting it using regex, python
Question: I have a data set which looks like thus,

    
    
    "See the new #Gucci 5th Ave NY windows customized by @troubleandrew for the debut of the #GucciGhost collection."
    "Before the #GucciGhost collection debuts tomorrow, read about the artist @troubleandrew"
    

So i am trying to get rid of all the @ AND the words attached to it. My
dataset should look something like this.

    
    
    "See the new #Gucci 5th Ave NY windows customized by for the debut of the #GucciGhost collection."
        "Before the #GucciGhost collection debuts tomorrow, read about the artist"
    

So i can use a simple replace statement to get rid of the `@`. But the
adjacent word is a problem.

I am using re to search/find the occurrence. But i am not able to delete this
word.

P.S -- If it was a single word, it would have not been a problem. But there
are multiple words here and there in my data set attached to `@`


Answer: You can use regex

    
    
    import re
    
    a = [ 
    "See the new #Gucci 5th Ave NY windows customized by @troubleandrew for the debut of the #GucciGhost collection.",
    "Before the #GucciGhost collection debuts tomorrow, read about the artist @troubleandrew"
    ]
    pat = re.compile(r"@\S+") # \S+ all non-space characters
    for i in range(len(a)):
        a[i] = re.sub(pat, "", a[i]) # replace it with empty string
    print a
    

This will give you what you want.

