排序题
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)
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)
相关文章推荐
- Shell 助力开发效率提升
- 十篇笔记走向Python测试开发之路四(字典)
- 十篇python笔记带你走向测试开发之路-第一篇
- mac os 使用pyenv管理python多版本
- Python学习笔记015——序列(字节数组 bytearray)
- 自定义日志
- 日志回滚:python(日志分割)
- python 连接 SAP HANA 数据库
- centos下安装python的过程
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- Python之scrapy实现的爬虫,百度贴吧的自动签到和自动发帖、自动回帖
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy