[Tutor] Finding all the letters in a string?
Andrew Nelsen
sxkorean at gmail.com
Tue Sep 18 01:21:09 CEST 2007
I was wondering, recently, the most expedient way to take a string with
[@#$%^&*] and alpha-numeric characters [ie. "^@%#*$@*$g@)$&^@&^$F"] and
place all of the letters in a string or list. I thought there could be
obvious ways:
A) Find all the letters, put them in a list, one by one. Something like (I'm
not sure yet how I'd do it...):
import string
list = {}
string = "@*&^$&*^@$g*(&@$*(&$@c(*&*(&c^&%&^%"
for x in string:
if x <is in string.letters?>
list = list + [x]
B) Delete all the characters in the string that don't match string.letters:
No idea...strip()?
Thanks,
Drew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070917/e85d0c67/attachment.htm
More information about the Tutor
mailing list