with open('winnernum.txt', 'r') as b:
data = b.readlines()
gone=(max(data))
print(gone)
with open("winnernum.txt","r") as h:
del gone
我在python中尝试过这段代码的其他变体,但仍然无法删除。我需要从一个文本文件中打印前5个最大的数字。你知道吗
我以前尝试过使用这个:
with open('winners.txt', 'r') as b:
data = b.readlines()
gone=(max(data))
print(gone)
import heapq
print(heapq.nlargest(5, winner))
但这并不总是能选出前五名,而且往往是随机挑选出来的。请帮帮我!你知道吗
试试这个:
下面是一个简单的解决方案:
相关问题 更多 >
编程相关推荐