My friend John and I are members of the "Fat to Fit Club (FFC)". John is worried because
each month a list with the weights of members is published and each month he is the last on the list
which means he is the heaviest. 

I am the one who establishes the list so I told him:
"Don't worry any more, I will modify the order of the list".
It was decided to attribute a "weight" to numbers. The weight of a number will be from now on
the sum of its digits. 

For example `99` will have "weight" `18`, `100` will have "weight"
`1` so in the list `100` will come before `99`.
Given a string with the weights of FFC members in normal order can you give this string ordered by "weights" of these numbers?

# Example:

`"56 65 74 100 99 68 86 180 90"` ordered by numbers weights becomes: 
`"100 180 90 56 65 74 68 86 99"`

When two numbers have the same "weight", let us class them as if they were strings (alphabetical ordering) and not numbers:
`100` is before `180` because its "weight" (1) is less than the one of `180` (9)
and `180` is before `90` since, having the same "weight" (9),  it comes before as a *string*.

All numbers in the list are positive numbers and the list can be empty.

# Notes

- it may happen that the input string have leading, trailing whitespaces and more than a unique whitespace between two consecutive numbers
- Don't modify the input
- For C: The result is freed.

Difficulty: EASY
Starter code: def order_weight(strng):
	

Solutions:
def order_weight(_str):
	return ' '.join(sorted(sorted(_str.split(' ')), key=lambda x: sum((int(c) for c in x))))


def sum_string(s):
	sum = 0
	for digit in s:
		sum += int(digit)
	return sum

def order_weight(strng):
	initial_list = sorted(strng.split())
	result = ' '.join(sorted(initial_list, key=sum_string))
	return result


def weight_key(s):
	return (sum((int(c) for c in s)), s)

def order_weight(s):
	return ' '.join(sorted(s.split(' '), key=weight_key))


def order_weight(strng):
	return ' '.join(sorted(strng.split(), key=lambda x: (sum((int(d) for d in x)), x)))


order_weight = lambda s: ' '.join(sorted(sorted(s.split(' ')), key=lambda i: sum(map(int, i))))


def order_weight(s):
	return ' '.join(sorted(s.split(), key=lambda x: (sum(map(int, x)), x)))


def order_weight(string):
	return ' '.join((c[1] for c in sorted(((sum((int(b) for b in a)), a) for a in string.split()))))


def order_weight(strng):
	nums = sorted(strng.split())
	weights = [sum(map(int, n)) for n in nums]
	res = [n for (w, n) in sorted(zip(weights, nums))]
	return ' '.join(res)


def order_weight(strng):
	return ' '.join(sorted(strng.split(' '), key=lambda s: (sum([int(i) for i in s]), s)))


def order_weight(strng):
	return ' '.join(sorted(sorted(strng.split()), key=lambda w: sum([int(c) for c in w])))


import operator
from functools import reduce

def order_weight(strng):
	ans = []
	d = {}
	members = strng.split()
	for weight in members:
		sum_weight = 0
		for digit in weight:
			sum_weight += int(digit)
		if d.get(sum_weight) != None:
			d[sum_weight].append(weight)
		else:
			d[sum_weight] = [weight]
	li = sorted(list(d.items()), key=lambda el: el[0])
	for pair in li:
		if len(pair[1]) > 1:
			for mean in sorted(pair[1]):
				ans.append(str(mean))
		else:
			ans.append(str(pair[1][0]))
	return ' '.join(ans)


def order_weight(s):
	return ' '.join(sorted(s.split(), key=lambda x: (sum((int(y) for y in x)), x)))


def order_weight(string):
	weights = string.split()
	return ' '.join(sorted(weights, key=lambda w: (sum((int(n) for n in w)), w)))


def order_weight(strng):
	l = list(strng.split())
	l = sorted(l)
	l = sorted(l, key=lambda x: sum((int(n) for n in str(x))))
	return ' '.join(l)


def get_digits_sum(number):
	return sum([int(sign) for sign in number if sign.isdigit()])

def custom_sorting(numbers):
	values = [(get_digits_sum(number), number) for number in numbers]
	return [value[1] for value in sorted(values)]

def order_weight(strng):
	return ' '.join(custom_sorting(strng.strip().split(' ')))


def order_weight(strng):
	return ' '.join([a[1] for a in sorted([(sum((int(y) for y in x)), x) for x in strng.split(' ')])])


def order_weight(strng):
	nums = strng.split()
	l = []
	for n in nums:
		s = sum(list((int(i) for i in n)))
		l += [[s, n]]
	l.sort()
	return ' '.join([i[-1] for i in l])


def order_weight(string):
	s = sorted([(sum([int(n) for n in num.strip()]), num.strip()) for num in string.split(' ')])
	return ' '.join(map(lambda t: t[1], s))


def order_weight(strng):
	my_list = sorted([int(i) for i in strng.split()], key=lambda x: str(x))
	sorted_int_list = sorted(my_list, key=lambda x: sum((int(d) for d in str(x))))
	return ' '.join(map(str, sorted_int_list))


def order_weight(strng):
	res = strng.split(' ')
	list = []
	for x in res:
		a = 0
		res2 = [z for z in x]
		for y in res2:
			a += int(y)
		list.append(a)
	answer = [m for (n, m) in sorted(zip(list, res))]
	return ' '.join(answer)


def order_weight(strng):
	if strng == '':
		return strng
	else:
		lss = strng.split()
		new_ls = []
		dic = {}
		value = ''
		for elements in lss:
			new = sum((float(element) for element in elements))
			if new in new_ls:
				while new in new_ls:
					new = float(new)
					new += 0.001
				new_ls.append(new)
				dic[new] = elements
			else:
				new_ls.append(new)
				dic[new] = elements
			new_ls.sort()
		sl = [dic.get(new_ls[m]) for m in range(len(new_ls))]
		for m in range(len(new_ls)):
			for n in range(len(new_ls)):
				if int(new_ls[m]) == int(new_ls[n]) and m != n:
					if dic.get(new_ls[m]) < dic.get(new_ls[n]) and m > n:
						t = new_ls[m]
						new_ls[m] = new_ls[n]
						new_ls[n] = t
		for i in range(len(new_ls) - 1):
			value += ''.join(dic.get(new_ls[i]))
			value += ' '
		value += ''.join(dic.get(new_ls[-1]))
		return value


def order_weight(strng):
	return ' '.join(sorted(sorted(filter(lambda x: not not x, strng.split(' '))), key=lambda x: sum(map(int, x))))


def order_weight(strng):
	strng = [list(map(int, i)) for i in strng.split(' ')]
	strng = sorted(sorted(strng), key=lambda num: sum(num))
	strng = ' '.join([''.join(map(str, i)) for i in strng])
	return strng


def order_weight(strng):
	nums = sorted(sorted(strng.split(' ')), key=lambda x: sum([int(i) for i in x]))
	return ' '.join(nums)


def order_weight(strng):
	st_list = strng.split()
	return ' '.join(sorted(st_list, key=lambda x: (sum((int(y) for y in x)), x)))


def order_weight(strng):
	return ' '.join(sorted(sorted(strng.split()), key=lambda s: sum(map(int, list(s)))))


def order_weight(strng):
	return ' '.join(sorted(strng.split(), key=lambda x: (sum(map(int, x)), str(x))))


order_weight = lambda s: ' '.join(sorted(sorted(s.split()), key=lambda w: sum(map(int, w))))


def order_weight(strng):
	return ' '.join(sorted(sorted(strng.split()), key=lambda num_str: sum((int(digit) for digit in num_str))))


def sumStr(strng):
	return sum((int(num) for num in strng))

def order_weight(strng):
	strList = sorted(strng.split(' '))
	return ' '.join(sorted(strList, key=sumStr))


def order_weight(strng):
	print(strng)

	def sum_strng(some_string):
		return sum((int(x) for x in some_string if x.isdigit()))
	original_string_array = strng.split(' ')
	tuple_arr = []

	def order(arr):
		for i in arr:
			tuple_arr.append((i, sum_strng(i)))
	order(original_string_array)
	tuple_arr.sort(key=lambda tup: tup[0])
	tuple_arr.sort(key=lambda tup: tup[1])
	return ' '.join([x[0] for x in tuple_arr])


def order_weight(strng):
	return ' '.join(sorted(strng.split(), key=lambda w: (sum(map(int, w)), w)))


def order_weight(string):
	valueList = [sum([int(char) for char in num]) for num in string.split()]
	return ' '.join([tup[1] for tup in sorted(zip(valueList, string.split()))])


from functools import cmp_to_key

def weight_str_nb(strn):
	return sum([int(d) for d in strn])

def comp(a, b):
	cp = weight_str_nb(a) - weight_str_nb(b)
	if cp == 0:
		if a < b:
			r = -1
		else:
			r = 1
	else:
		r = cp
	return r

def order_weight(strng):
	return ' '.join(sorted(strng.split(), key=cmp_to_key(comp)))


def order_weight(string):
	string = string.split()
	string = sorted(string)
	string = sorted(string, key=f)
	return ' '.join(string)

def f(n):
	return sum((int(i) for i in n))


def order_weight(strng):
	s = strng.split()
	s2 = []
	s3 = []
	order = []
	Out = []
	s4 = ''
	for i in range(len(s)):
		s2.append(int(s[i]))
		a = 0
		for j in range(len(s[i])):
			a = a + s2[i] // 10 ** j % 10
		s3.append(a)
	for j in range(len(s3) - 1):
		for m in range(len(s3) - 1):
			buf = 0
			buf2 = 0
			if s3[m] > s3[m + 1]:
				buf = s3[m]
				s3[m] = s3[m + 1]
				s3[m + 1] = buf
				buf2 = s2[m]
				s2[m] = s2[m + 1]
				s2[m + 1] = buf2
			elif s3[m] == s3[m + 1]:
				if str(s2[m]) > str(s2[m + 1]):
					buf2 = s2[m]
					s2[m] = s2[m + 1]
					s2[m + 1] = buf2
	for m in range(len(s2)):
		s4 = s4 + str(s2[m]) + ' '
	s5 = ''
	for j in range(len(s4) - 1):
		s5 = s5 + s4[j]
	return s5


def convert(x):
	return sum(map(int, x))

def GT(x, y):
	return convert(x) > convert(y)

def LT(x, y):
	return convert(x) < convert(y)

def EQ(x, y):
	return convert(x) == convert(y)

def qSort(xs):
	if len(xs) == 0:
		return []
	(pivot, *xs) = xs
	lower = [x for x in xs if LT(x, pivot)]
	eqs = sorted([x for x in xs if EQ(x, pivot)] + [pivot])
	upper = [x for x in xs if GT(x, pivot)]
	return qSort(lower) + eqs + qSort(upper)

def order_weight(xs):
	return ' '.join(qSort(xs.split(' ')))


def order_weight(strng):
	return ' '.join(sorted(sorted(strng.split()), key=lambda x: sum((int(a) for a in x)), reverse=False))


order_weight = lambda strng: ' '.join([x for (_, x) in sorted(zip([sum([int(j) for j in i]) for i in strng.split(' ')], strng.split(' ')))])


def order_weight(strng):
	return ' '.join(map(str, sorted(sorted(list((x for x in strng.split(' ') if x)), key=lambda x: str(x)), key=lambda x: sum(map(int, str(x))))))


def order_weight(string):
	return ' '.join(sorted(string.split(), key=lambda s: (sum((int(d) for d in list(s))), s)))


def sort_key(s):
	return (sum((int(n) for n in list(s))), s)

def order_weight(strng):
	return ' '.join(sorted(strng.split(), key=sort_key))


def order_weight(strng):
	if len(strng) > 1:
		stg = strng.split()
		k = []
		for i in stg:
			l = 0
			for m in i:
				l += int(m)
			k.append(l)
		q = list(zip(k, stg))
		q.sort(key=len, reverse=True)
		p = sorted(q, key=lambda t: (t[0], t))
		print(p)
		v = list(zip(*p))
		return ' '.join(v[1])
	else:
		return strng


def order_weight(strng):
	slw = [(sum((int(x) for x in str(weight))), weight) for weight in strng.split()]
	return ' '.join((x[1] for x in sorted(slw)))


def order_weight(string):
	return ' '.join(sorted(string.split(), key=lambda x: (sum((int(i) for i in x)), x)))


def order_weight(st):
	(res, l) = ([], st.split(' '))
	d = {x: sum(map(int, list(l[x]))) for x in range(len(l))}
	print(d)
	for x in sorted(set(d.values())):
		res.extend(sorted([l[i] for i in d.keys() if d[i] == x]))
	return ' '.join(res)


def order_weight(strng):
	strng_list = strng.split(' ')
	lst = list(zip(map(lambda x: sum((int(i) for i in x)), strng_list), strng_list))
	stl = list(map(lambda x: x[1], sorted(lst, key=lambda x: (x[0], x[1]))))
	return ' '.join((s for s in stl))


order_weight = lambda numbers: ' '.join(sorted(numbers.split(), key=lambda number: (sum((int(num) for num in number)), number)))


def order_weight(string):
	strng = string.split()
	for i in range(0, len(strng)):
		for j in range(0, len(strng)):
			if weight(strng[i]) < weight(strng[j]):
				pass
			elif weight(strng[i]) == weight(strng[j]):
				if strng[i] <= strng[j]:
					pass
				else:
					print(strng[i], strng[j])
					(strng[i], strng[j]) = (strng[j], strng[i])
			else:
				print(strng[i], strng[j])
				(strng[i], strng[j]) = (strng[j], strng[i])
	strng.reverse()
	final = ' '.join(strng)
	return final

def weight(st):
	weight = 0
	for i in range(len(st)):
		weight = weight + int(st[i])
	return weight


def order_weight(string):
	return ' '.join(sorted(string.split(), key=lambda x: (sum([int(s) for s in x]), x), reverse=False))


def digit_sum(string):
	return sum([int(x) for x in string])

def order_weight(string):
	weights = sorted(string.split())
	return ' '.join(sorted(weights, key=digit_sum))


def weight(s):
	return (sum((int(char) for char in s)), s)

def order_weight(string):
	lst = string.split()
	lst.sort(key=weight)
	return ' '.join(lst)


def order_weight(strng):
	lis = strng.split(' ')
	c = []
	for word in lis:
		weight = 0
		for num in word:
			weight += int(num)
		x = {}
		x['number'] = word
		x['weight'] = weight
		c.append(x)
	c.sort(key=lambda x: x['number'])
	c.sort(key=lambda x: x['weight'])
	return ' '.join((x['number'] for x in c))
	print(order_weight(strng))


def order_weight(strng):
	cs = strng.strip().split()
	ls = sorted(sorted(cs), key=cc)
	return ' '.join(ls)

def cc(a):
	return sum(map(int, a))


def getSum(n):
	return sum([int(x) for x in n])

def order_weight(s):
	return ' '.join(sorted(s.split(), key=lambda x: [getSum(x), x]))


def sum_digits(a):
	n = int(a)
	r = 0
	while n:
		(r, n) = (r + n % 10, n // 10)
	return r

def order_weight(strng):
	strng_sorted = sorted(strng.split(), key=str.lower)
	return ' '.join(sorted(strng_sorted, key=sum_digits))


def order_weight(strng):
	weight_list = strng.split()
	faux_list = []
	for weight in weight_list:
		total = 0
		for number in weight.strip():
			total = total + int(number)
		(faux_weight, real_weight) = (total, weight)
		faux_list.append((faux_weight, real_weight))
	final_manipulated_list = []
	for (x, y) in sorted(faux_list):
		final_manipulated_list.append(y)
	return ' '.join(final_manipulated_list)


def order_weight(strng):
	weights = list()
	for x in strng.split():
		weights.append(sum([int(y) for y in x]))
	weight_counts = list(zip(strng.split(), weights))
	return ' '.join(('{!s}'.format(key) for (key, value) in sorted(weight_counts, key=lambda t: t[::-1])))


def sum_digits(num):
	return sum([int(d) for d in num])

def order_weight(string):
	if string == '':
		return string
	weights = [(sum_digits(num), num) for num in string.split()]
	weights.sort()
	answer = [weights[i][1] for (i, _) in enumerate(weights)]
	return ' '.join(answer)


def order_weight(strng):

	def sorter(num):
		return sum([int(digit) for digit in num])
	strng_nums = strng.strip().split()
	strng_nums.sort()
	strng_nums.sort(key=sorter)
	return ' '.join(strng_nums)


def order_weight(strng):
	strng_lst = sorted(strng.split())
	weights = [(weight, sum([int(digit) for digit in weight])) for weight in strng_lst]
	sorted_weights = [result[0] for result in sorted(weights, key=lambda result: result[1])]
	return ' '.join(sorted_weights)


def order_weight(strng):
	sum_sort = lambda x: sum([int(n) for n in x])
	return ' '.join(sorted(sorted(strng.split()), key=sum_sort))


import functools
import operator

def order_weight(strng):
	if strng == '':
		return ''
	else:
		x = strng.split(' ')
		y = []
		weighted_weights = dict()
		for item in range(len(x)):
			actualweight = x[item]
			y.append(functools.reduce(operator.add, [int(actualweight[i]) for i in range(len(actualweight))]))
			weighted_weights[x[item]] = y[item]
		x = sorted(x)
		listofweights = sorted(x, key=weighted_weights.get)
		return ' '.join(listofweights)


def order_weight(strng):
	codeList = []
	counter = 0
	finalString = ''
	wgList = strng.split(' ')
	for i in range(len(wgList)):
		for j in range(len(wgList[i])):
			counter = counter + int(wgList[i][j])
		codeList.append(counter)
		counter = 0
	finalList = sorted(list(zip(codeList, wgList)))
	for i in range(len(finalList)):
		finalString += finalList[i][1] + ' '
	return finalString[:-1]


def order_weight(strng):
	numbers = [int(i) for i in strng.split()]
	weights_list = [sum(map(int, str(number))) for number in numbers]
	weights_list_sorted = sorted(weights_list)
	weights = []
	for number in numbers:
		weight = sum(map(int, str(number)))
		mylst = [number, weight]
		weights.append(mylst)
	res_list = []
	for lst in sorted(weights, key=lambda x: (x[1], str(x[0]))):
		res_list.append(str(lst[0]))
	return ' '.join(res_list)


import operator

def order_weight(strng):
	modified = [(sum(map(int, x)), x) for x in strng.split()]
	return ' '.join((sort[1] for sort in sorted(modified, key=operator.itemgetter(0, 1))))


def order_weight(strng):
	strng = sorted(strng.split())
	result = sorted(strng, key=lambda elem: sum([int(x) for x in elem]))
	return ' '.join(result)


def order_weight(strng):
	result = 0
	solution = []
	numbers_list = [int(x) for x in strng.split()]
	for x in numbers_list:
		while x > 0:
			result += x % 10
			x = x // 10
		solution.append(result)
		result = 0
	return ' '.join([x for (_, x) in sorted(zip(solution, [str(x) for x in numbers_list]))])


def order_weight(strng):
	wghts = strng.split()
	srtd = sorted(wghts, key=lambda x: (get_weight(x), x))
	return ' '.join((str(i) for i in srtd))

def get_weight(number):
	return sum((int(digit) for digit in number))


def order_weight(strng):
	list2 = strng.split(' ')
	weights = []
	for x in list2:
		digits = list(x)
		for i in range(len(digits)):
			digits[i] = int(digits[i])
		weights.append(sum(digits))
	(weights, list2) = zip(*sorted(zip(weights, list2)))
	return str(','.join(list2)).replace(',', ' ')


from functools import cmp_to_key

def sum_digits(num):
	return sum([int(d) for d in str(num)])

def sort_weights(w1, w2):
	w1_total = sum_digits(w1)
	w2_total = sum_digits(w2)
	if w1_total == w2_total:
		if str(w1) < str(w2):
			return -1
		return 1
	else:
		return w1_total - w2_total

def order_weight(strng):
	if not strng:
		return ''
	weights = [int(x) for x in strng.split(' ')]
	sorted_weights = sorted(weights, key=cmp_to_key(sort_weights))
	return ' '.join(map(str, sorted_weights))


def order_weight(strng):
	splitted = strng.split()
	solution = ''
	list = []
	for item in splitted:
		weight = 0
		for digit in item:
			weight += int(digit)
			arr = [weight, item]
		list.append(arr)
	list.sort()
	for item in list:
		solution += ' ' + item[1]
	return solution[1:]