按字符前的数字自然排序Unicode列表


scores2 = [u'4H', u'10H', u'18H', u'59H', u'84H', u'19A', u'38A', u'65A', u'88A', u'90A', u'']

Scores 2输出如下:有人能告诉我如何从列表中删除unicode,然后按数字值排序,所以最后一个字母没有排序的操作?我看过自然排序,但我确定这只适用于字母之前的数字?

scores2 = [u'4H', u'10H', u'18H', u'59H', u'84H', u'19A', u'38A', u'65A', u'88A', u'90A', u'']
print(sorted((x.encode("utf-8") for x in scores2 if x.strip()), key=lambda x:int(x[:-1])))
['4H', '10H', '18H', '19A', '38A', '59H', '65A', '84H', '88A', '90A']

最新更新