Answer the question
In order to leave comments, you need to log in
Why is this code snippet not working?
This code should take a numeric int value and then sort it in descending order
def descending_order(num):
output = [x for x in str(num)]
return output.sort(reverse=True)
Answer the question
In order to leave comments, you need to log in
The sort method returns nothing. So it is necessary to separate sorting and return.
Or, you can use sorted instead of sort:
def descending_order(num):
return sorted(str(num), reverse=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question