8/9 Iteration Confusion


#1

https://www.codecademy.com/en/courses/python-beginner-en-qzsCL/1/4?curriculum_id=4f89dab3d788890003000096

The code I have is correct but I would really appreciate someone explaining to me how the for loops works. What I do not understand is how student in students iterates through each students assigned dictionary list values when students was never assigned any values as a variable.

I suspect it has something to do with the concept of passing arguments but I cannot find information on this that gets the point across.

Many thanks in advance.

def get_class_average(students):
    results = []
    for student in students:
        results.append(get_average(student))
    return(average(results))

#2

This is a list of object identifiers that points to each dictinary. It acts as an index.

student in students

The iterator variable takes one value at a time from the list. It now points to one dictionary.


#3

Thank you for your response.

How does students point to each dictionary without it being previously specified? That is the part that confuses me and I feel there is a simple concept that I'm missing.

Apologies if I'm not being clear enough or if this is a silly question.

Thanks again.


#4

student => [
    lloyd    # first iteration
    alice    # second
    tyler    # third iteration
] in students

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.