basic questions on cmp, < and sort
Fredrik Lundh
fredrik at pythonware.com
Thu Oct 26 02:48:51 EDT 2006
Schüle Daniel wrote:
> first question
>
> In [117]: cmp("ABC",['A','B','C'])
> Out[117]: 1
>
> against what part of the list is the string "ABC" compared?
http://docs.python.org/lib/comparisons.html
"Objects of different types, except different numeric types and
different string types, never compare equal; such objects are
ordered consistently but arbitrarily (so that sorting a hetero-
geneous array yields a consistent result)"
> class X does not implement < and cmp
> what is this comparision is based on?
"objects of the same types that don't support proper comparison
are ordered by their address"
> third question
>
> sort([[1,2,3],["ABC"],['Z','A'], X(), 4)
>
> how does python handle heterogenous items in the list
> in this case?
"Objects of different types, except different numeric types and
different string types, never compare equal; such objects are
ordered consistently but arbitrarily (so that sorting a hetero-
geneous array yields a consistent result)"
> first I assumed
no, first you assumed that this wasn't documented.
</F>
More information about the Python-list
mailing list