Re: How to sort this without 'cmp=' in python 3?

2023-10-24 Thread Chris Angelico via Python-list
On Wed, 25 Oct 2023 at 13:02, Mike H via Python-list wrote: > Is it possible to use lambda expression instead of defining a `Key` class? > Something like `sorted(my_list, key = lambda x, y: x+y > y+x)`? Look up functools.cmp_to_key. ChrisA --

Re: How to sort this without 'cmp=' in python 3?

2023-10-24 Thread Mike H via Python-list
On Saturday, October 15, 2016 at 12:27:42 AM UTC-7, Peter Otten wrote: > 38016...@gmail.com wrote: > > > nums=['3','30','34','32','9','5'] > > I need to sort the list in order to get the largest number string: > > '953433230' > > > > nums.sort(cmp=lambda a,b: cmp(a+b, b+a), reverse=True) >

Re: How to sort this without 'cmp=' in python 3?

2016-10-15 Thread 380162267qq
在 2016年10月14日星期五 UTC-4下午7:35:08,38016...@gmail.com写道: > nums=['3','30','34','32','9','5'] > I need to sort the list in order to get the largest number string: '953433230' > > nums.sort(cmp=lambda a,b: cmp(a+b, b+a), reverse=True) > > But how to do this in python 3? > > Thank you !I learn

Re: How to sort this without 'cmp=' in python 3?

2016-10-15 Thread Peter Otten
38016226...@gmail.com wrote: > nums=['3','30','34','32','9','5'] > I need to sort the list in order to get the largest number string: > '953433230' > > nums.sort(cmp=lambda a,b: cmp(a+b, b+a), reverse=True) > > But how to do this in python 3? > > Thank you While cmp_to_key is neat doing it by

Re: How to sort this without 'cmp=' in python 3?

2016-10-14 Thread breamoreboy
On Saturday, October 15, 2016 at 12:53:48 AM UTC+1, sohca...@gmail.com wrote: > On Friday, October 14, 2016 at 4:35:08 PM UTC-7, 38016...@gmail.com wrote: > > nums=['3','30','34','32','9','5'] > > I need to sort the list in order to get the largest number string: > > '953433230' > > > >

Re: How to sort this without 'cmp=' in python 3?

2016-10-14 Thread Ned Batchelder
On Friday, October 14, 2016 at 7:49:33 PM UTC-4, Robin Koch wrote: > Am 15.10.2016 um 01:33 schrieb 38016226...@gmail.com: > > nums=['3','30','34','32','9','5'] > > I need to sort the list in order to get the largest number string: > > '953433230' > > > > nums.sort(cmp=lambda a,b: cmp(a+b, b+a),

Re: How to sort this without 'cmp=' in python 3?

2016-10-14 Thread Ben Finney
38016226...@gmail.com writes: > nums=['3','30','34','32','9','5'] > I need to sort the list in order to get the largest number string: '953433230' > nums.sort(cmp=lambda a,b: cmp(a+b, b+a), reverse=True) For demonstration, I'll re-write this such that the names and output make more sense::

Re: How to sort this without 'cmp=' in python 3?

2016-10-14 Thread sohcahtoa82
On Friday, October 14, 2016 at 4:35:08 PM UTC-7, 38016...@gmail.com wrote: > nums=['3','30','34','32','9','5'] > I need to sort the list in order to get the largest number string: '953433230' > > nums.sort(cmp=lambda a,b: cmp(a+b, b+a), reverse=True) > > But how to do this in python 3? > >

Re: How to sort this without 'cmp=' in python 3?

2016-10-14 Thread Robin Koch
Am 15.10.2016 um 01:33 schrieb 38016226...@gmail.com: nums=['3','30','34','32','9','5'] I need to sort the list in order to get the largest number string: '953433230' nums.sort(cmp=lambda a,b: cmp(a+b, b+a), reverse=True) But how to do this in python 3?

How to sort this without 'cmp=' in python 3?

2016-10-14 Thread 380162267qq
nums=['3','30','34','32','9','5'] I need to sort the list in order to get the largest number string: '953433230' nums.sort(cmp=lambda a,b: cmp(a+b, b+a), reverse=True) But how to do this in python 3? Thank you -- https://mail.python.org/mailman/listinfo/python-list