Re: An isalpha() that accepts underscores as well

2006-03-01 Thread egbert
In the discussion about isalpha()_mutants that accept underscores as well, we did not talk about regular expressions. Afterwards I did some timings. My first observation was that the whole experiment is rather futile, because it takes only about a second to do a million tests. If you take the tro

Re: An isalpha() that accepts underscores as well

2006-02-26 Thread Alex Martelli
Zajcev Evgeny <[EMAIL PROTECTED]> 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, whil

Re: An isalpha() that accepts underscores as well

2006-02-26 Thread Zajcev Evgeny
"Fuzzyman" <[EMAIL PROTECTED]> writes: > Zajcev Evgeny wrote: >> egbert <[EMAIL PROTECTED]> writes: >> >> > The string method isalpha() returns True when all characters in the >> > string are alphabetic. Unfortunately the underscore is not alphabetic. >> > A function that does what I need is: >> >

Re: An isalpha() that accepts underscores as well

2006-02-26 Thread Fuzzyman
Zajcev Evgeny wrote: > egbert <[EMAIL PROTECTED]> writes: > > > The string method isalpha() returns True when all characters in the > > string are alphabetic. Unfortunately the underscore is not alphabetic. > > A function that does what I need is: > > > > def alfa_(w): > > return "".join(w.spl

Re: An isalpha() that accepts underscores as well

2006-02-26 Thread Zajcev Evgeny
egbert <[EMAIL PROTECTED]> writes: > The string method isalpha() returns True when all characters in the > string are alphabetic. Unfortunately the underscore is not alphabetic. > A function that does what I need is: > > def alfa_(w): > return "".join(w.split("_")).isalpha() > > but for the ki

Re: An isalpha() that accepts underscores as well

2006-02-26 Thread bearophileHUGS
This is probably faster: def alfa_(w): return w.replace("_", "a").isalpha() This is another solution, but it's probably slower, you can time it: from string import letters _setalpha = set(letters + "_") def alfa_2(w): return not (set(w) - _setalpha) Bye, bearophile -- http://mail.py

An isalpha() that accepts underscores as well

2006-02-26 Thread egbert
The string method isalpha() returns True when all characters in the string are alphabetic. Unfortunately the underscore is not alphabetic. A function that does what I need is: def alfa_(w): return "".join(w.split("_")).isalpha() but for the kind of strings that I have this is about ten times