我尝试按编号顺序对文本文件进行排序(首先显示最高值),每个值都在新行上。下面是我存储在.txt文件中的数据示例,每次用户完成测验时都会写入该文件。你知道吗
'Anton v1'0 'Antonv2'0 'Henry'0 'Joe'0 'Berty'0 'Lee'0 'Antttton'1
'Anton22'0
到目前为止,我已经找到了如何按字母顺序排列它们,这解决了我的部分问题:
with open('class1.txt', 'r') as r:
for line in sorted(r):
print(line, end='')
Tags:
试试这个:
下面是一个如何使用
csv
模块以及如何使用自定义键对数据进行排序的示例。你知道吗首先,几个实用函数:
现在,我们可以加载你的数据文件
这给了我们
整理一下
结果是
你可以像这样写回文件
而生产
相关问题 更多 >
编程相关推荐