string methods (warning, newbie)

Jimmy Retzlaff jimmy at retzlaff.com
Sat Feb 26 21:15:34 EST 2005


Anthonyberet wrote:
> Is there a string mething to return only the alpha characters of a
string?
> eg 'The Beatles - help - 03 - Ticket to ride', would be
> 'TheBeatlesTickettoride'
> 
> If not then how best to approach this?
> I have some complicated plan to cut the string into individual
> characters and then concatenate a new string with the ones that return
> true with the .isalpha string method.
> 
> Is there an easier way?

The approach you are considering may be easier than you think:

>>> filter(str.isalpha, 'The Beatles - help - 03 - Ticket to ride')
'TheBeatleshelpTickettoride'

Jimmy



More information about the Python-list mailing list