这是我的代码,用于导入文件,将其添加到列表中,并将列表从高到低排序:
for x in range (1):
scoresList = [ ] #this is a variable for the list
file = open("Leaderboard file.txt", "r") #this opens the file as a read file
file_line = file.readlines() #this then reads the lines
scoresList.append(file_line) #this then appends the lines to the list
file.close()
leaderboard_list = sorted(scoresList, reverse=True) #this is supposed to order the numbers yet it doesnt seem to do anything
print(leaderboard_list)
start_menu()
这是它打印出来的:
[['\n', "35['jerry'] 20['bill']15['Dan']20['billy']"]]
这是它获取信息的文件:
35['jerry'] 20['bill']15['Dan']20['billy']
嗯,那比我想象的要长一点
输出:
这将返回已排序的大写元组列表(每行)。如果您的文本格式是关键的,您将不得不做一些更多的工作从这里。如果它是关键的
帮助来自:
Collect every pair of elements from a list into tuples in Python
How to sort (list/tuple) of lists/tuples?
Python - How to convert only numbers in a mixed list into float?
相关问题 更多 >
编程相关推荐