在字符之前按字母排序的自然类型的Unicode列表

时间:2015-07-27 17:42:37

标签: python beautifulsoup

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

分数2打印出这样的, 有人可以告诉我如何从列表中删除unicode,然后按数字值排序,以便最后一个字母没有操纵排序?我见过自然排序,但我确定这只适用于数字之前的字母?

1 个答案:

答案 0 :(得分:1)

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']