我是靠谱客的博主 潇洒大象,这篇文章主要介绍python字符串按首字母排序,Python按字母順序排序字符串,首先是小寫,现在分享给大家,希望可以做个参考。

I want to sort a given array of strings alphabetically using python, but lowercase words should appear first.

我想使用python按字母順序對給定的字符串數組進行排序,但首先應出現小寫字。

An example:

一個例子:

#!/usr/local/bin/python2.7

arr=['A','e','a','D','f','B']

arr.sort()

for s in arr: print s

Input:

輸入:

A

e

a

D

f

B

Output (current):

輸出(當前):

A

B

D

a

e

f

Output (should be):

輸出(應該):

a

e

f

A

B

D

5 个解决方案

#1

6

Use a custom key method which checks whether the item is not .lower() and then compares the items itself. For 'A', 'D' and 'B' not x.islower() will return True and for

最后

以上就是潇洒大象最近收集整理的关于python字符串按首字母排序,Python按字母順序排序字符串,首先是小寫的全部内容,更多相关python字符串按首字母排序内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(182)

评论列表共有 0 条评论

立即
投稿
返回
顶部