账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    列表sorted()报错
    29
    0

    现在有一个一个列表:
    files = ['T1.fas', 'T10.fas', 'T11.fas', 'T12.fas', 'T13.fas', 'T14.fas', 'T15.fas', 'T16.fas', 'T17.fas', 'T18.fas', 'T19.fas', 'T2.fas', 'T20.fas', 'T21.fas', 'T22.fas', 'T23.fas', 'T24.fas', 'T25.fas', 'T26.fas', 'T27.fas', 'T28.fas', 'T29.fas', 'T3.fas', 'T30.fas', 'T31.fas', 'T32.fas', 'T33.fas', 'T34.fas', 'T35.fas', 'T36.fas', 'T37.fas', 'T38.fas', 'T39.fas']
    我想将其按照T后面的数字排列,即T1.fas,T2.fas.....

    我是这样写的,但是报错了

    sorted(files, key=lambda x: int(x.split('.')[0][1:]))
    ValueError: invalid literal for int() with base 10: ''

    请教该怎么写将他排序

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部