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 -- http://mail.python.org/mailman/listinfo/python-list