basic questions on cmp, < and sort

"Martin v. Löwis" martin at v.loewis.de
Thu Oct 26 01:29:13 EDT 2006


Schüle Daniel schrieb:
> first question
> 
> In [117]: cmp("ABC",['A','B','C'])
> Out[117]: 1
> 
> against what part of the list is the string "ABC" compared?

The names of the types are compared:

py> cmp("string", "list")
1

> second question
> 
> In [119]: class X(object):
>    .....:     pass
>    .....:
> 
> In [120]: X() < X()
> Out[120]: True
>
> what is this comparision is based on?

The addresses of the objects, in main memory.

> third question
> 
> sort([[1,2,3],["ABC"],['Z','A'], X(), 4)
> 
> how does python handle heterogenous items in the list
> in this case?

pair-by-pair. It is quite difficult to impose a total
order on all objects; this will go away in Python 3.

Regards,
Martin



More information about the Python-list mailing list