Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: what's the effect of cmp here? (http://www.velocityreviews.com/forums/t947983-re-whats-the-effect-of-cmp-here.html)

Dave Angel 07-10-2012 03:11 PM

Re: what's the effect of cmp here?
 
On 07/10/2012 11:01 AM, levi nie wrote:
> what's the effect of cmp here? The bList and cList is the same at last.
>
> code:
> aList=[3,2,5,4]
>
> bList=aList[:]
> bList.sort()
> print "bList is",bList
>
> cList=aList[:]
> cList.sort(cmp)
> print "cList is",cList
>
>


The main effect is for the reader of the code. When you supply your own
callback to sort(), you're being explicit about how you want the items
to be compared. If the default works for you, then you can omit
supplying a function.




--

DaveA



All times are GMT. The time now is 05:53 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.