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'
> >
> > nums.sort(cmp=lambda a,b: cmp(a+b, b+a), reverse=True)
> >
> > But how to do this in python 3?
> >
> > Thank you
>
> You don't need a lambda in this case.
>
> Sort the strings in reverse order:
> nums.sort(reverse=True)
>
> Create a string:
> biggestNum = ''.join(nums)
>
> Or in a single line, which doesn't change the original value of nums:
> biggestNum = ''.join(sorted(nums, reverse=True))

## Advertising

No, you've made exactly the same mistake that I did :(
>>> nums=['3','30','34','32','9','5']
>>> wants='953433230'
>>> nums.sort(reverse=True)
>>> result = ''.join(nums)
>>> result == wants
False
>>> result
'953432303'
--
https://mail.python.org/mailman/listinfo/python-list