[Tutor] Finding all the letters in a string?

Eric Lake ericlake at ubuntu.com
Tue Sep 18 02:12:44 CEST 2007

On Mon, Sep 17, 2007 at 07:48:56PM -0400, Michael Langford wrote:
>    Not my night...the second sentence "To get the set of letters, use"
>    should read "To get the filtered string".....time for more Coke Zero.
>           --Michael

>    On 9/17/07, Andrew Nelsen <[6] 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
>      _______________________________________________

I missed a part too. The original question specified alpha-numeric
characters. sting.ascii.letters will only get a - z and A - Z. Would a
regular expression work here with \w? 

Eric Lake
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 481 bytes
Desc: Digital signature
Url : http://mail.python.org/pipermail/tutor/attachments/20070917/b534a6a7/attachment.pgp 

More information about the Tutor mailing list