Ad

I use the variable number as a string to use it as a array, sort it and return it as a ingeter again

Code
Diff
  • def maxnum(number):
        lista = []
        result = ""
        for char in str(number):
            lista.append(char)
        lista.sort(reverse = True)
        for char in lista:
            result = result + char
        return int(result)
    • maxnum = lambda n: int(n) if len(str(n)) == 1 else int(n) if len({*str(n)}) == 1 else int(n) if len(str(n)) < str(n).count("0")*2 else n if n < 100 and n % 10 == 0 else int(sorted([i for i in range(int("".join(sorted([*str(n)])[::-1])) + 1) if sorted([*str(i)]) == sorted([*str(n)])])[::-1][1]) if sorted([i for i in range(int("".join(sorted([*str(n)])[::-1])) + 1) if sorted([*str(i)]) == sorted([*str(n)])])[::-1][0] == n else int(sorted([i for i in range(int("".join(sorted([*str(n)])[::-1])) + 1) if sorted([*str(i)]) == sorted([*str(n)])])[::-1][0])
    • def maxnum(number):
    • lista = []
    • result = ""
    • for char in str(number):
    • lista.append(char)
    • lista.sort(reverse = True)
    • for char in lista:
    • result = result + char
    • return int(result)