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
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
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
--
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 kind of strings
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.split(_)).isalpha()
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:
def alfa_(w):
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, while it would