I am trying to write a function that given a list of non negative integers, arranges them such that they form the largest possible number.
For example, given
One-liner using insights from Antti Haapala, PM 2Ring and Stefan Pochmann:
from fractions import Fraction sorted(a, key=lambda n: Fraction(n, 10**len(str(n))-1), reverse=True)
Given a = [50, 5, 51, 59, 2, 1, 9, 98]:
a = [50, 5, 51, 59, 2, 1, 9, 98]
[9, 98, 59, 5, 51, 50, 2, 1]