Calculating student and class averages I am currently going through Codecademy's Python course (I don't come from a coding background but I'm thoroughly enjoying it) and I got to the end of one of the sections and thought, "Well it worked, but that seemed wildly inefficient."  I tried shortening unnecessary parts and came up with this:

lloyd = {
    "name": "Lloyd",
    "homework": [90.0, 97.0, 75.0, 92.0],
    "quizzes": [88.0, 40.0, 94.0],
    "tests": [75.0, 90.0]
}
alice = {
    "name": "Alice",
    "homework": [100.0, 92.0, 98.0, 100.0],
    "quizzes": [82.0, 83.0, 91.0],
    "tests": [89.0, 97.0]
}
tyler = {
    "name": "Tyler",
    "homework": [0.0, 87.0, 75.0, 22.0],
    "quizzes": [0.0, 75.0, 78.0],
    "tests": [100.0, 100.0]
}

classlist = [lloyd, alice, tyler]

# Add your function below!

def get_average(student):
    average_homework = sum(student["homework"]) / len(student["homework"])
    average_quizzes = sum(student["quizzes"]) / len(student["quizzes"])
    average_tests = sum(student["tests"]) / len(student["tests"])
    average_total = average_homework * 0.1 + average_quizzes * 0.3 + average_tests * 0.6
    return average_total

def get_letter_grade(score):
    if score &gt;= 90:
        return "A"
    if score &lt; 90 and score &gt;= 80:
        return "B"
    if score &lt; 80 and score &gt;= 70:
        return "C"
    if score &lt; 70 and score &gt;= 60:
        return "D"
    else:
        return "F"

def get_class_average(classlist):
    a = []
    for student in classlist:
        a.append(get_average(student))
    return sum(a) / len(a)

get_class_average(classlist)


Now this bit works, but I was wondering if there are more places I could trim the code down without losing the functionality (I'm guessing there is in the get_average function but the things I tried came back as errors because of the "name" field in the dictionary). Codecademy seems good for learning the fundamentals, but I wanted to get some insight into the "best" way to do things.  Should I not worry about reworking functional code to be more efficient at first and just learn the fundamentals, or should I keep trying to make the "best" code as I learn?
In the function get_letter_grade you were checking more conditions then necessary. Try to follow the logical difference between your function and my code. It is simple math which I used to optimize it. Also structuring it as an if-elif-...-else is better for readability.
In get_average and get_class_average I use a thing called list comprehension. A simple google search will tell you what it is and why it is better. Google it in python tutorials if you have problem.


Edited Functions

def average(values):
    return sum(values) / len(values)

def get_average(student):
    keys = ['homework', 'quizzes', 'tests']
    factors = [0.1, 0.3, 0.6]
    return sum([ average(student[key]) * factor for key, factor in zip(keys, factors)])

def get_letter_grade(score):
    if score &gt;= 90:
        return "A"
    elif score &gt;= 80:
        return "B"
    elif score &gt;= 70:
        return "C"
    elif score &gt;= 60:
        return "D"
    else:
        return "F"

def get_class_average(classlist):
    return average([get_average(student) for student in classlist])

get_class_average(classlist)