An isalpha() that accepts underscores as well
Alex Martelli
aleaxit at yahoo.com
Sun Feb 26 15:13:01 EST 2006
Zajcev Evgeny <zevlg at yandex.ru> wrote:
...
> > The following will work, and probably only be twice as slow as
> > 'isalpha' :-) :
> >
> > def alfa(w):
> > return w.replace('_', '').isalpha()
>
> Yeah, great performance indeed, thanks!
Except it rejects a w that's JUST an underscore, while it would accept a
w that's just a letter, which seems weird to me. Using 'a' as the
second argument of the replace call, as somebody else suggested, appears
to produce a more sensible uniformity.
Alex
More information about the Python-list
mailing list