Linux 拨号vps windows公众号手机端

python字符串降序排序怎么实现

lewis 7年前 (2018-01-02) 阅读数 6 #程序编程
文章标签 python

可以使用sorted函数对字符串进行降序排序,然后使用join方法将排好序的字符重新组合成一个字符串。示例如下:

s = "hello world"
sorted_s = ''.join(sorted(s, reverse=True))
print(sorted_s)

输出结果为:

wroolldlh e
版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门