with open("main.json") as f:
lvs = json.load(f)
v1_sorted_by_lvl = sorted(lvs.items(), key=lambda e: e[1]["money"], reverse=True)
write = []
for i, (k, v) in enumerate(v1_sorted_by_lvl, start=1):
write.append(f'{i} `{k}` | {v["money"]}')
print("\n".join(write))
How can I mark only the 10th place in the ranking code above?
python json
i is the rank. We can just spin the for loop until i reaches 10, and then we can go out of the loop when i reaches the loop.
For, when you go out of the loop, you can use break.
It's simple, right?
582 Uncaught (inpromise) Error on Electron: An object could not be cloned
849 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
589 GDB gets version error when attempting to debug with the Presense SDK (IDE)
562 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.