Explain this concept of code in brief Functions Code snippet

opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)
def extract(index):
    column = []    
    for row in apps_data[1:]:
        value = row[index]
    return column

Here, index what is the index value here no clue also why do we use the
value = row[index] statement

for row in apps_data[1:]:
    value = row[index]

please explain the logic of the three lines of code and what are we supposed to see as result and the return value command does not return anything whie running the code

1 Like

Hi @sagarnihalani99,

The return value is not returning because you are not calling the extract function like this:

genres = extract(11)

Observe that in the above code, we provided 11 as an argument to the function. This value will be stored in the index parameter specified in the function definition (def extract(index):).

apps_data[1:] is returning all rows in apps_data except the first row (header).

for row in apps_data[1:]:

For each row (except header row)

value = row[index] (will become value = row[11])

Get the value stored in index position 11 and assign it to a variable called value


Append this value to the column list.

And when the loop is finished, we are returning the column list which contains all the values we just extracted.