Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25133
| Date | 2012-07-10 11:11 -0400 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: what's the effect of cmp here? |
| References | <CAEMsKDsPBVMveXD1Z0yV9zkstzO87Sk438bCsS-=shdffAwXhw@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1986.1341933140.4697.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: what's the effect of cmp here? Dave Angel <d@davea.name> - 2012-07-10 11:11 -0400
csiph-web