python - How to remove punctuation in between words -
i use code strip line of text punctuation:
line = line.rstrip("\n") line = line.translate(none, string.punctuation)   the problem words doesn't turn doesnt want remove punctuation between words can't seem figure out way so. how should go this?
edit: thought using strip() function take effect on right , left trailing of whole sentence.
for example:
isn't ., stackoverflow - best ?   should become:
isn't stackoverflow best   instead of current output:
isnt stackoverflow best      
assuming consider words groups of characters separated spaces:
>>> string import punctuation >>> line = "isn't ., stackoverflow - best ?" >>> ' '.join(word.strip(punctuation) word in line.split()               if word.strip(punctuation)) "isn't stackoverflow best"   or
>>> line = "isn't ., stackoverflow - best ?" >>> ' '.join(filter(none, (word.strip(punctuation) word in line.split()))) "isn't stackoverflow best"      
Comments
Post a Comment