Combining functions: why do we have to define a list in the "mean()" function

opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

def extract(data_set, index):
    column = []    
    for row in data_set[1:]:
        value = row[index]
    return column

def find_sum(a_list):
    a_sum = 0
    for element in a_list:
        a_sum += float(element)
    return a_sum

def find_length(a_list):
    length = 0
    for element in a_list:
        length += 1
    return length

def mean(data_set, index):
    column = []
    column = extract(data_set, index)
    mean = find_sum(column)/find_length(column)
    return mean

avg_price = mean(apps_data, 4)

I get the correct answer.
But I don’t understand why I have to define a list in the “mean()” function when there is a list defined in the “extract()” function which the “mean()” function refers to.



1 Like

Hi Christophe,

Welcome to the Community!

You mean why do we have to define an empty list inside the mean function? Indeed, we don’t have to do so. If you drop this line from the mean function:

column = []

it will will work perfectly anyway.

1 Like