Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Search faster?
#1
Whoops, put the wrong title! That was another thing I was trying.

I have a simple homework webpage.

PHP collects the students answers, compares them with the correct answers and marks them.

Then the score is written to a MySQL table against that student's student number.

All I have to do is export the columns student_nr and score each week from the results table and I have all the results in a csv file.

I save the csv as an Excel, then Python takes over. I open the excel file and read the student number as key and the score as value into a dictionary: studentsScores

Now I read the scores into a blanko results file containing all the students' numbers in column 1

# put HW scores in the results file
for key in studentScores.keys():
    try:
        for rowNum in range(2, blankoFilerows + 1):
            if str(key) == str(blankoFile[clas].cell(row=rowNum, column=1).value):                  
                blankoFile[clas].cell(row=rowNum, column=4, value=studentScores[key])                
    except KeyError:
        pass
I am just wondering, is there a more "Pythonic", more elegant and quicker way to do this?

For each student, I run through all the keys, 163 * 163. (Just for this course)

Can that be done quicker? (Not that this takes more than a second, but I'm just wondering if there is another, better way)

I am reading a book from Reuven Lerner, Python Workout, he has some neat tricks!
Reply
#2
Please show the structure of studentScores.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  go over and search in numpy array faster caro 7 1,691 Jun-20-2022, 04:54 PM
Last Post: deanhystad
  How can I make a faster search algorithm pianistseb 19 6,397 Apr-18-2019, 05:48 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020