0
0
0xbadc0ffee2020-08-11 16:50:10
Python
0xbadc0ffee, 2020-08-11 16:50:10

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)

But for some reason the function doesn't return anything.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2020-08-11
@0xbadc0ffee

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)

D
Dr. Bacon, 2020-08-11
@bacon

read the doc on sort

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question