Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a way of improving this leaderboard system?
So me and my friend came up with this as a leaderboard system and im wondering are there any improvements that can be made to it? especially in the sorting section?

#prototype leaderboards

import csv

score=input("whats ya score")
username=input("whats ya name")

with open ("protleader.csv", "a", newline='') as file:
    fields=['score', 'name']
    writer=csv.DictWriter(file, fieldnames=fields)
    writer.writerow({'score' : score, 'name' : username})

with open ("protleader.csv", "r") as file:
    for i in reader:
for i in range(len(sortlist)):
    if i != 0:


for i in range(len(sortlist)):

for i in range(555):
    for i in range(len(sortlist)-1):
        if i != 0:
            if sortlist[i][0] < sortlist[i+1][0]:


print("Sorted and cut:")
for i in range(len(sortlist)-1):
Which i does if i != 0: refer to, the first or second for i in
for i in range(555):
    for i in range(len(sortlist)-1):
        if i != 0: 
As woooee implies, you are using the variable name i way to much. Use more descriptive variable names. Also, loop directly over lists, not their indices. Not like this:

for i in range(len(sortlist)):
But like this:

for score in sortlist:
sortlist is another bad name. Okay, it's a list you're going to sort. What is it a list of? That would make a better name.

You don't need to write your own sort, there is a very efficient one built in:

sortlist.sort(key row: row[0])
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Login System Carbonix 4 248 Feb-04-2019, 02:19 PM
Last Post: Larz60+
  Python version 3 that seems to be ignored by the system on a Raspberry Pi Discret68 3 205 Dec-28-2018, 06:42 PM
Last Post: Gribouillis
  Tips for CLI program with Keybinding system pedropessoa 2 182 Nov-21-2018, 09:59 AM
Last Post: Gribouillis
  run command on system with multi qoutes evilcode1 16 771 Aug-31-2018, 05:19 PM
Last Post: evilcode1
  Python inventory system with dicts. 2skywalkers 7 385 Aug-23-2018, 05:06 PM
Last Post: ichabod801
  Improving Efficiency of SVM by various available kernels Sachtech 0 311 Apr-09-2018, 07:29 AM
Last Post: Sachtech
  Beginner: System of Equations Mahdi1994 2 545 Mar-19-2018, 12:37 AM
Last Post: Tiskolin
  Python login system help. calumw20 1 582 Mar-06-2018, 08:01 AM
Last Post: buran
  Lottery System on my mobile website nooxm123 1 479 Feb-06-2018, 10:55 AM
Last Post: j.crater
  Detecting Windows System Sounds? crash2720 1 485 Jan-23-2018, 07:08 PM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)