Create a function that takes a list of one or more non-negative integers, and arranges them such that they form the largest possible number.

Examples:

`largestArrangement([4, 50, 8, 145])` returns 8504145 (8-50-4-145)

`largestArrangement([4, 40, 7])` returns 7440 (7-4-40)

`largestArrangement([4, 46, 7])` returns 7464 (7-46-4)

`largestArrangement([5, 60, 299, 56])` returns 60565299 (60-56-5-299)

`largestArrangement([5, 2, 1, 9, 50, 56])` returns 95655021 (9-56-5-50-21)

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Combinatorics

Starter code: def largest_arrangement(numbers):
	

Solutions:
from functools import cmp_to_key
cmp = lambda a, b: int('%i%i' % (b, a)) - int('%i%i' % (a, b))
largest_arrangement = lambda n: int(''.join((str(i) for i in sorted(n, key=cmp_to_key(cmp)))))


def largest_arrangement(numbers):
	numbers = list(map(str, numbers))
	for x in range(len(numbers)):
		for j in range(len(numbers)):
			ab = numbers[x] + numbers[j]
			ba = numbers[j] + numbers[x]
			if int(ab) > int(ba):
				(numbers[x], numbers[j]) = (numbers[j], numbers[x])
	return int(''.join(numbers))


from itertools import permutations

def largest_arrangement(numbers):
	return max((int(''.join(p)) for p in permutations(map(str, numbers))))


from itertools import permutations

def largest_arrangement(numbers):
	return int(max((''.join(r) for r in permutations(list(map(str, numbers)))), key=int))


from itertools import permutations, groupby

def largest_arrangement(a):
	a = sorted(a, key=lambda x: str(x)[0])[::-1]
	t = ''
	for (i, j) in groupby(a, key=lambda x: str(x)[0]):
		li = []
		for k in permutations(list(j)):
			li.append(int(''.join(map(str, k))))
		t += str(max(li))
	return int(t)


from functools import cmp_to_key

def largest_arrangement(numbers):

	@cmp_to_key
	def cmp(a, b):
		return int(b + a) - int(a + b)
	return int(''.join((n for n in sorted(map(str, numbers), key=cmp))))


from itertools import permutations
from collections import defaultdict

def find_largest(lst):
	candidates = map(''.join, permutations(lst))
	return max(candidates)

def largest_arrangement(numbers):
	first_digit = defaultdict(list)
	for n in map(str, numbers):
		first_digit[n[0]].append(n)
	result = ''.join((find_largest(first_digit[d]) for d in '9876543210'))
	return int(result)


def largest_arrangement(numbers):
	r = qsort(numbers)
	r = ''.join([str(v) for v in r])
	return int(r)

def qsort(arr):
	if len(arr) <= 1:
		return arr
	else:
		return qsort([x for x in arr[1:] if so(x, arr[0]) == -1]) + [arr[0]] + qsort([x for x in arr[1:] if so(x, arr[0]) != -1])

def so(a, b):
	return -1 if str(b) + str(a) < str(a) + str(b) else 1


largest_arrangement = lambda a: (lambda l: int(''.join(sorted(map(str, a), key=lambda s: s.ljust(l, s[0]))[::-1])))(len(str(max(a))))