html_log:jeff 1153.3 1.84 625:54 1 2 71 3 2 10 7:58 499 3 5 616:36 241 36
html_log:fred 28.7 1.04 27:34 -10 18 13 0:48 37 18 8 -3.63
html_log:bob 1217.1 1.75 696:48 1 5 38 6 109 61 14:42 633 223 25 435:36 182 34
... continues
上面是文本文件。現在python正則表達式前10名
mystats = fo.readlines()
fo.close()
change = str(mystats)
pattern = re.compile("html_log:(?P<name>[^ ]*) (?P<score>[^ ]*)")
mylist=sorted(pattern.findall(change), key=lambda x: float(x[1]), reverse=True)
我的輸出是
bob 1217.1
jeff 1153.3
fred 28.7
問題.. 我想不過來獲得第五int值和我的輸出應該是
bob 5
jeff 2
fred 18
我不知道模式僅匹配第5個值。
我沒有看到「前10名」與您的問題有關?你是在輸入的第5個元素之後(如你的例子所示),還是排序後的第5個元素? –