string methods (warning, newbie)
Christos TZOTZIOY Georgiou
tzot at sil-tec.gr
Mon Feb 28 16:46:16 EST 2005
On Sun, 27 Feb 2005 18:12:17 -0700, rumours say that Steven Bethard
<steven.bethard at gmail.com> might have written:
[snip Nick Coghlan's list comprehension]
[STeVe]
>On the other hand, filter doesn't do the same thing:
>
>py> s = u'The Beatles - help - 03 - Ticket to ride'
>py> filter(str.isalpha, s)
>Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
>TypeError: descriptor 'isalpha' requires a 'str' object but received a
>'unicode'
>py> ''.join(c for c in s if c.isalpha())
>u'TheBeatleshelpTickettoride'
This works though:
.>> filter(type(s).isalpha, s)
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
More information about the Python-list
mailing list