'20' <= 100
Steven Taschuk
staschuk at telusplanet.net
Fri May 2 12:08:20 EDT 2003
Quoth I:
[...]
> Those who want comparisons never to raise exceptions might be
> happy with a solution in which, say, all normal strings are < all
> Unicode strings. This makes all the comparisons determinate, at
> least, but it would lead to counterintuitive behaviour in simple
> cases: we'd have, for example, 'x' < u'x', while naïvely one would
> expect 'x' == u'x' (which is true at present).
Another possibility, no doubt mentioned before:
def cmpstr(s1, s2):
for c1, c2 in map(None, s1, s2):
if c1 is None:
return -1
elif c2 is None:
return 1
else:
diff = cmp(ord(c1), ord(c2))
if diff:
return diff
else:
return 0
All such comparisons are determinate; the result is consistent
with the present meaning of < in cases where < does not raise an
exception.
The weird thing about this cmpstr is that it extends the privilege
presently enjoyed by ASCII to ISO-8859-1:
>>> cmpstr('ma\xEFs', u'ma\N{LATIN SMALL LETTER I WITH DIAERESIS}s')
0
--
Steven Taschuk staschuk at telusplanet.net
"I tried to be pleasant and accommodating, but my head
began to hurt from his banality." -- _Seven_ (1996)
More information about the Python-list
mailing list