我有一个discord.py命令,它通过json创建排行榜
cogs/coins.json(字典)如下所示:
{
"781524858026590218": {
"name": "kvbot test platform",
"total_coins": 129,
"data": {
"564050979079585803": {
"name": "Bluesheep33",
"coins": 127
},
"528647474596937733": {
"name": "ACAT_",
"coins": 2
}
}
(json文件中带数字的绿色字符串是discord guild/成员ID)
如何使代码更短更清晰
谢谢你提前帮忙,因为我真的不知道解决办法
当涉及到在一个dict中查找(排序)前十项时,这种方法要比反复检查dict并在那里做不同的事情容易得多
还有一些更好的代码,比如用于安全访问的
Dict.get
基于JSON数据示例
相关问题 更多 >
编程相关推荐