您的位置:首页 > 编程语言 > Python开发

排序题

2018-04-09 20:06 92 查看
CodeWars上的排序题
Your task is to make a function that can take any non-negative integer as a argument and return it with its digits in descending order.
Essentially, rearrange the digits to create the highest possible number.
Examples:
Input: 21445 Output: 54421
Input: 145263 Output: 654321

Input: 1254859723 Output: 9875543221def descend_range(number):
num = []
if (number<0):
print("Please enter a non-negative number")
else:
for i in range(len(str(number))):
num.append(str(number)[i])
num = ''.join(sorted(num, reverse=True))
print(num)

num = 18754984586
descend_range(num)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  CodeWars Python