关闭
Hit
enter
to search or
ESC
to close
May I Suggest ?
#leanote #leanote blog #code #hello world
柯仓无居所
Home
Archives
Tags
Search
python list 中带有数字排序方法
? python ?
? list 排序 ?
? 大数字 ?
? 排序 ?
694
0
0
swimming
? python ?
? list 排序 ?
? 大数字 ?
? 排序 ?
> python 中list有sort()函数可以排序,但是排序遇到大数字时,会发现不灵,只能按照第一个数字排序 ---- > 本实例可以除去此问题,具体方法如下: ```python import re def tryint(s): try: return int(s) except: return s def alphanum_key(s): return [tryint(c) for c in re.split("([0-9]+)", s)] # 使用方法 a = ['meet_160089', 'meet_70199', 'meet_170987', 'meet_160099',] a.sort(key=alphanum_key) ```
觉得不错,点个赞?
提交评论
Sign in
to leave a comment.
No Leanote account ?
Sign up now
.
0
条评论
More...
文章目录
No Leanote account ? Sign up now.