A little help.
>>> import string
>>> string.ascii_letters
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> string.punctuation
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
>>>
In this code i excludestring.ascii_letters
import string
exclude = string.ascii_letters
s = 'test.. hi? for ,,,'
punc_text = ''.join(ch for ch in s if ch not in exclude)
print punc_text #.. ? ,,,
I keep getting an error message saying raw_input isn't defined?
If you are using python 3 changeraw_input() to input()
a.remove(p) will never work because string method dos not have a remove method.
snippsat
Practically a Posting Shark
808 posts since Aug 2008
Reputation Points: 353
Solved Threads: 294
You can also use re to remove all characters with the W flag.
Just to give a little more info about this.
richieking is talking about regular expression. http://docs.python.org/library/re.html
Her is a demo of how it work.
Using findall is an easy option,search and match are to other option to read about.
>>> import re
>>> r = re.findall(r'\W', 'test.. hi? for ,,,')
>>> r
['.', '.', ' ', '?', ' ', ' ', ',', ',', ',']
>>> #Make it a string
>>> ''.join(r)
'.. ? ,,,'
>>>
snippsat
Practically a Posting Shark
808 posts since Aug 2008
Reputation Points: 353
Solved Threads: 294