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
  Cannot add dot executable to system path bobsmith76 2 155 Mar-05-2019, 03:17 PM
Last Post: bobsmith76
  Login System Carbonix 4 382 Feb-04-2019, 02:19 PM
Last Post: Larz60+
  Improving Efficiency of SVM by various available kernels Sachtech 0 368 Apr-09-2018, 07:29 AM
Last Post: Sachtech
  Beginner: System of Equations Mahdi1994 2 619 Mar-19-2018, 12:37 AM
Last Post: Tiskolin
  Python login system help. calumw20 1 694 Mar-06-2018, 08:01 AM
Last Post: buran
  how to do comparison for the value returned by os.system jash 2 788 Nov-11-2017, 11:09 AM
Last Post: snippsat
  Need Help With Python RPG Battle System SBanya 0 1,459 Nov-07-2017, 06:05 PM
Last Post: SBanya
  Login System ItsBlueey 1 6,458 Nov-06-2017, 05:24 PM
Last Post: heiner55
  Grade System Help jamisontboyd 3 1,093 Oct-03-2017, 11:11 PM
Last Post: ichabod801
  Why does this hang the system up Able98 15 3,047 Sep-02-2017, 09:50 PM
Last Post: nilamo

Forum Jump:

Users browsing this thread: 1 Guest(s)