Indentation explanation

Can anyone explain why my line of code doesn’t work, but it does with ‘indentations’

Thanks

Screen Link:

https://app.dataquest.io/c/112/m/315/functions%3A-fundamentals/7/creating-frequency-tables

My Code:

Replace this line with your code
def freq_table(column):
    column_table = {}
    for value in column:
        if value in column_table:
            column_table[value] += 1
        else:
            column_table[value] = 1
        return column_table

genres_ft = freq_table(genres)  

What I expected to happen:

genres = extract(11)

def freq_table(column):
    column_table = {}
    for value in column:
        if value in column_table:
            column_table[value] += 1
        else:
            column_table[value] = 1
    return column_table

genres_ft = freq_table(genres)  

What actually happened: 

Replace this line with the output/error


<!--Enter other details below: -->

Pay closer attention to when the return statement is executed

  • Inside the for loop, or
  • Outside the for loop