313-9 the else clause

# INITIAL 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])
    # Complete code from here
# SOLUTION CODE
for app in apps_data[1:]:
    price = float(app[4])   
    if price == 0.0:
        app.append('free')
    else:
        app.append('non-free')

apps_data[0].append('free_or_not')
print(apps_data[:6])

Hi, first question, pls let me know if this is not the best place.

I don’t understand how this solution add a new category to the list of apps?
thanks

hi @Paolo

To answer your first question, DQ Community is run by Gandalf’s cousin but who is much wiser. As of today:

Coming to the second question:

apps_data is a list of lists. and app is one list or row in that list of lists.

append is a method that adds an element/ value to the end of a list.

so app.append(element) will extend the element as the last value in the list.

image

hope it helped.

1 Like

Hi Rucha,
Thanks for the reply,
Just be patient with me, trying to get the foundations right.

What I’m confused (I can solve the exercises, but what to fully understand what is what and why) is “app”, being a list, it already exist and I don’t need to specify it right?

As a list ‘app’ it refers to the full table with all the apps details (rows and columns)?

Hope it makes sense what I’m asking.
Cheers
Paolo

hey @Paolo

apps_data is a list of lists with the rows and columns like structure.

app on the other hand is a variable that we create while using a For Loop. This variable will then store each and every row from the apps_data. One row at a time! from first row to last row in the apps_data list of lists.
image

“app” here is the name of the variable. You may find different names for this in various examples in and out of DQ.

such as element, item, row, each_row, each_element etc.

The idea behind this is, we need to perform some operation on every row of apps_data, but one at a time.

Let us know if you still have doubts. Perhaps, the better moderators of DQ will help us both!.

Just in case you wish to explore on your own, DQ comm already has various posts with queries on this topic and moderators have explained them excellently. You can try surfing through them.

1 Like

Thanks! Now it’s clear, I must have got confused at some point and this thing about ‘app’ was slowing me down. Thanks for the great explanation and the patience, I’m still getting used to where to find the informations. Cheers. Paolo

1 Like