1 Star 0 Fork 14

Joe/ant-learn-python-100P

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
p012_sort_grade_file.py 661 Bytes
一键复制 编辑 原始数据 按行查看 历史
cztps2 提交于 2021-04-11 23:54 . xx
def read_file():
result = []
with open("./student_grade_input.txt") as fin:
for line in fin:
line = line[:-1]
result.append(line.split(","))
return result
def sort_grades(datas):
return sorted(datas,
key=lambda x: int(x[2]),
reverse=True)
def write_file(datas):
with open("./student_grade_output.txt", "w") as fout:
for data in datas:
fout.write(",".join(data) + "\n")
# 读取文件
datas = read_file()
print("read_file datas:", datas)
# 排序数据
datas = sort_grades(datas)
print("sort_grades datas:", datas)
# 写出文件
write_file(datas)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/stayhungry2022/ant-learn-python-100P.git
[email protected]:stayhungry2022/ant-learn-python-100P.git
stayhungry2022
ant-learn-python-100P
ant-learn-python-100P
master

搜索帮助