-1

I want to make number sorter that can sort number: Input: 90213 Output: 93210 Here is my code:

broj = int(input())
b = [broj]
print(b.sort(reverse=True))

When it runs it outputs None.

  • 1
    Welcome! Sort does not return any value, that is why you get None. You need to print the list. – Michele Dorigatti Jan 26 '20 at 10:03
  • Does this answer your question? [Python list sort in descending order](https://stackoverflow.com/questions/4183506/python-list-sort-in-descending-order) – shiv_90 Jan 26 '20 at 10:59

2 Answers2

1

This will do the trick:

broj = input()

print(''.join(sorted(broj, reverse=True)))
Grzegorz Skibinski
  • 12,624
  • 2
  • 11
  • 34
0

You don't have to convert it to a int:

value = input()  # value is a string
sorted_value = sorted(value, reverse=True)  # sorted_value is a list like ['9', '3', '2', '1', '0']
print("".join(sorted_value))  # "".join() joins all the elements from the list to one string
bb1950328
  • 1,403
  • 11
  • 18