Why can't I xor strings?
Paul Rubin
http
Fri Oct 8 17:51:11 EDT 2004
dataangel <k04jg02 at kzoo.edu> writes:
> To save time the first thing my function does is check if
> I'm comparing an empty vs. a non-empty string, because they are to be
> never considered similar.
> Right now I have to write out the check like this:
>
> if str1 and str2:
> if not str1 or not str2:
> return 0
How about:
def nonempty(s):
return (len(s) > 0)
and then
if nonempty(str1) != nonempty(str2):
return 0
Of course there's other ways to write the same thing. Python 2.3 has
a "bool" function which when called on a string, returns true iff the
string is nonempty.
More information about the Python-list
mailing list