[Tutor] Finding all the letters in a string?

Michael Langford mlangford.cs03 at gtalumni.org
Tue Sep 18 01:47:00 CEST 2007


At first I totally misread this....

To get the set of letters, use

import string
string.ascii_letters

Then do what you said in your algorithm.

A shorthand way to do that is

filteredString = ''.join([c for c in foo if c in string.ascii_letters])

-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.TierOneDesign.com/
Entertaining: http://www.ThisIsYourCruiseDirectorSpeaking.com

On 9/17/07, Andrew Nelsen <sxkorean at gmail.com> wrote:
>
> 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
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070917/72a4092e/attachment.htm 


More information about the Tutor mailing list