订单清单元素

时间:2019-11-07 20:02:25

标签: python python-3.x

我要订购一个字符串列表:

JWTVerifier verifier = JWT.require(ALGORITHM).withIssuer(ISSUER).build();
DecodedJWT decoded = verifier.verify(jwt);

if (blacklistService.find(jwt.getId())) {
    throw new JWTVerificationException();
}

User user = userService.loadByUsername(jwt.getClaim("username").asString());

if (user.getDenyBefore() != null && user.getDenyBefore().compareTo(jwt.getIssuedAt()) > 0) {
    throw new JWTValidationException();
}

当我使用排序功能

MyList = ['dataset1', 'dataset3','dataset2','dataset10','dataset100','dataset11']

我明白了

X = sorted(MyList)

我想得到

['dataset1', 'dataset10','dataset100','dataset11','dataset2','dataset3']

预先感谢您的回答

1 个答案:

答案 0 :(得分:0)

问题在于,排序在传入字符串时会使用字符串比较。您可以删除数据集,然后仅使用整数进行排序

X = sorted(MyList, key=lambda x: int(x.replace("dataset","")))