Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python remove hashtag symbol and keep key words

I want to remove hashtag symbol ('#') and underscore that separate between words ('_')

Example: "this tweet is example #key1_key2_key3"

the result I want: "this tweet is example key1 key2 key3"

My code using string :

#Remove punctuation , # Hashtag Symbol 
translate_table = dict((ord(char), None) for char in string.punctuation)   
cleaned_combined_tweets.translate(translate_table)

which gives the result: "this tweet is example key1key2key3"

like image 342
Noura Avatar asked Feb 08 '18 08:02

Noura


1 Answers

>>> "this tweet is example #key1_key2_key3".replace("#", "").replace("_", " ")
like image 168
pylang Avatar answered Oct 19 '22 07:10

pylang