1 Star 8 Fork 1

diyanqi / TastickOJ

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
paiming.py 674 Bytes
一键复制 编辑 原始数据 按行查看 历史
diyanqi 提交于 2020-08-13 11:49 . %%%
import json
import os
def read_file_as_str(file_path):
# 判断路径文件存在
if not os.path.isfile(file_path):
raise TypeError(file_path + " does not exist")
all_the_text = open(file_path).read()
# print type(all_the_text)
return all_the_text
def sort():
users=json.loads(read_file_as_str("users.json"))
ul=[]
ret={}
for key in users:
user_level=users[key]['level']
ul.append({"user":key,"level":user_level})
ul.sort(key = lambda x:x["level"])
cnt=0
for i in range(len(ul)-1,-1,-1):
cnt+=1
ret[str(cnt)]={"user":ul[i]['user'],"level":ul[i]['level']}
return json.dumps(ret)
Python
1
https://gitee.com/diyanqi07/TastickOJ.git
git@gitee.com:diyanqi07/TastickOJ.git
diyanqi07
TastickOJ
TastickOJ
master

搜索帮助