0

Checking Task

Help me plz to decide some task. Write a function that will take a list of non-negative integers, sort them so that they make up the largest possible number. For example, [50, 2, 1, 9], the largest generated number is 95021. My trying: mass = [9, 988, 9, 9, 82] def max_num(): b="" a=[str(m) for m in mass] for i in sorted(a, reverse=True): b+=i print (b) It not true. My result: 98899982, but should be 99998882

2nd Oct 2017, 5:08 PM
Shoblin86
2 Réponses
+ 4
from __future__ import division a = [50, 5, 51, 59, 2, 1, 9, 98] def fractionalize(i): divisor = 9 while divisor < i: divisor = 10 * divisor + 9 return i / divisor print(sorted(a, key=fractionalize, reverse=True))
2nd Oct 2017, 5:23 PM
Krafty Coder
Krafty Coder - avatar
+ 1
Malcolm , thank you.
2nd Oct 2017, 5:43 PM
Shoblin86