As one comment mentioned, it could be also done using regular expressions, which is again a separate topic and we will see usage of regular expression module(re) in python with help of some puzzles in coming posts.
Just copy the long input string in place of long input text here as a triple quoted string and assign it to messy_str as shown in second line of code below.
You can download the python file here and run it, if python is installed on your system.
import string
messy_str = """long input text here"""
punc=string.punctuation
spaces=string.whitespace
clean_str=messy_str.translate(None,punc)
clean=clean_str.translate(None,spaces)
print clean
No comments:
Post a Comment