If/else doubt when iterating

Screen Link:

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])
    # Complete code from here
    if price == 0.0:
        apps_data.append("free")
    else: 
        apps_data.append("not free")
    
apps_data[0].append('free_or_not') # column added  
print(apps_data[:6])```

What I expected to happen:
I expected it to the output to be exactky as mentioned in the solution . Basically , 

What actually happened: 

The solution says that apps_data is longer than we expected . Upon checking the solution , I noticed that after writing the if statement , i had added apps_data.append(“free”) line to be executed whereas the solution states that I have to add app.append(‘free’) . My question is why ?? Why did my statement not work here because ideally , after the If condition is satisfied , the app_data list should be appended and NOT app


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

Hi @RishabhKaul

You can see apps_data=list(read_file) which means 'apps_data` contains the whole list.

When you are using the loop, for app in apps_data[1:]: , – app represents the rows in the list of lists without the header. If the if criteria satisfies, the new labels either free or not has to be added at the end of each of these rows. Hence we use app to append.

Did this clarify your doubt?

Thanks a lot Jithin . Really helpful!

Great to hear that. If it solved your question, please mark it as solved. Thank you.