Blue Week Special Offer | Brighten your week!

Condition statement- problem 9

My Code:

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

for app in apps_data[1:]:
    price = float(app[4])
    if price == 0.0:

i didn’t get wrong with the code.

however, what I feel weird is:

in the for loop, I use append on list of app to add ‘free’ or ‘non_free’ label

why does the list of apps_data also add ‘free’ or ‘non_free’ label simultaneously ?

thank you for your help.

1 Like

Hi @rclr2009531,

Welcome to the Community!

Inside the loop, we were applying the labelling operations to all the sub-lists (let’s call them so) inside the list of lists apps_data starting from the second sub-list. Then after, outside the loop, we added a string 'free_or_not' only once, to the end of the first sub-list of the list of lists. Now, each sub-list has the same length, or in other words, the same number of items, as it was from the beginning. We can say that the first sub-list of apps_data (the one with the index 0) represents a list of column names for all the other sub-lists.