<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
No problem. As for the main use of <tt>cmp()</tt>, btw, afaik, it's
used to define custom sorting, as in the following:<br>
<br>
<tt>>>> import random<br>
>>> temp = []<br>
>>> for i in range(10):<br>
temp.append((random.randint(0,100),random.randint(0,100),random.randint(0,100)))<br>
<br>
<br>
>>> temp<br>
[(16, 70, 87), (57, 80, 33), (14, 22, 2), (21, 92, 69), (40, 18, 90),
(60, 78, 35), (3, 98, 7), (32, 21, 39), (15, 67, 15), (70, 95, 39)]<br>
>>> temp.sort(cmp=lambda x, y: cmp(x[0],y[0]))<br>
>>> temp<br>
[(3, 98, 7), (14, 22, 2), (15, 67, 15), (16, 70, 87), (21, 92, 69),
(32, 21, 39), (40, 18, 90), (57, 80, 33), (60, 78, 35), (70, 95, 39)]<br>
>>> temp.sort(cmp=lambda x, y: cmp(x[1],y[1]))<br>
>>> temp<br>
[(40, 18, 90), (32, 21, 39), (14, 22, 2), (15, 67, 15), (16, 70, 87),
(60, 78, 35), (57, 80, 33), (21, 92, 69), (70, 95, 39), (3, 98, 7)]<br>
>>> temp.sort(cmp=lambda x, y: cmp(x[2],y[2]))<br>
>>> temp<br>
[(14, 22, 2), (3, 98, 7), (15, 67, 15), (57, 80, 33), (60, 78, 35),
(32, 21, 39), (70, 95, 39), (21, 92, 69), (16, 70, 87), (40, 18, 90)]<br>
<br>
</tt>or, without lambdas:<br>
<tt><br>
>>> def sort(x,y):<br>
return cmp(x[0],y[0])<br>
<br>
>>> def sort1(x,y):<br>
return cmp(x[1],y[1])<br>
<br>
>>> def sort2(x,y):<br>
return cmp(x[2],y[2])<br>
<br>
>>> temp.sort(cmp=sort)<br>
>>> temp<br>
[(3, 98, 7), (14, 22, 2), (15, 67, 15), (16, 70, 87), (21, 92, 69),
(32, 21, 39), (40, 18, 90), (57, 80, 33), (60, 78, 35), (70, 95, 39)]<br>
>>> temp.sort(cmp=sort1)<br>
>>> temp<br>
[(40, 18, 90), (32, 21, 39), (14, 22, 2), (15, 67, 15), (16, 70, 87),
(60, 78, 35), (57, 80, 33), (21, 92, 69), (70, 95, 39), (3, 98, 7)]<br>
>>> temp.sort(cmp=sort2)<br>
>>> temp<br>
[(14, 22, 2), (3, 98, 7), (15, 67, 15), (57, 80, 33), (60, 78, 35),
(32, 21, 39), (70, 95, 39), (21, 92, 69), (16, 70, 87), (40, 18, 90)]</tt><br>
<br>
Rinzwind wrote:
<blockquote
cite="mid4677730601261200y3f3e5190wf5e0c3df9cd5e90c@mail.gmail.com"
type="cite">Thank you!<br>
*opens manual again*<br>
<br>
Wim<br>
<br>
<div><span class="gmail_quote">On 1/26/06, <b
class="gmail_sendername">Orri Ganel</b> <<a
href="mailto:singingxduck@gmail.com">singingxduck@gmail.com</a>>
wrote:</span>
<blockquote class="gmail_quote"
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Well,
the <tt>cmp()</tt> function does this if you compare the number
to 0:<br>
<br>
<tt>>>> cmp(-34,0)<br>
-1<br>
>>> cmp(0,0)<br>
0<br>
>>> cmp(23,0)<br>
1<br>
<br>
</tt>Of course, that's not all <tt>cmp()</tt> is good for, but it
would work in this case.<br>
<br>
HTH,<br>
Orri<br>
<span class="sg">
<pre cols="72">--
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.</pre>
</span></blockquote>
</div>
<br>
<pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Tutor maillist - <a class="moz-txt-link-abbreviated" href="mailto:Tutor@python.org">Tutor@python.org</a>
<a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a>
</pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Email: singingxduck AT gmail DOT com
AIM: singingxduck
Programming Python for the fun of it.</pre>
</body>
</html>