Blue Week Special Offer | Brighten your week!
days
hours
minutes
seconds

In Else Clause Mission Section why Append new string to First row of Data Set but not the Last?

Screen Link: https://app.dataquest.io/m/313/conditional-statements/9/the-else-clause

Can somebody please help me understand why in the instruction to the Else Clause mission section the new string ‘free_or_not’ is appended to the first row of the apps_data data set?

The new labels being added is, after all, to the end of each row which then creates a new column at the end… The solution is however as follows:

apps_data[0].append('free_or_not')

I do not understand why it should not rather be:

apps_data[-1].append('free_or_not')

Hi @victorvisagie987,
I believe there’s already a list apps_data[0] outside the for loop. Whatever name you call that list is what you’ll use with the list.append method.
Note that you’re not not specifying an index with the append method, rather you’re appending each app in the free_or_not category to the created list, one after another for every iteration.

P.S: I may not have really understood your question

1 Like

Hi Victor,
Did anyone answer to your question (or did you figure this out?)
I m wondering the same here…
Thanks

1 Like

Hi there Gaelle,
No, I unfortunately still don’t get it…
Thanks for bumping the question though!

Hello @victorvisagie987 @gaelle.c,

apps_data[0] is used to access the first list/row in the apps_data list of lists which is the header row in this dataset
while
apps_data[-1] is used to access the last list/row in the apps_data list of lists

So when you use the code apps_data[0].append('free_or_not') , it means that it should append the string 'free_or_not' to the fist row/list, which in turn creates a new column at the end of the first row.

while the code apps_data[-1].append('free_or_not') means that it should append the string `‘free_or_not’ to the last row/list.

I hope this answers your question.

Thanks, after rereading the initial instruction slowly I now understand where I got confused. :+1:

1 Like

Hi,

could you please help me understand why " apps_data[:1].append(“free_or_not”) " is not working.
apps_data[:1] and apps_data[0] fetches same Header.

Thanks in advance,

Hello @jaisonkmani, welcome to the community!

  1. What do you mean by apps_data[:1].append(“free_or_not”) " is not working?
    apps_data[:1].append("free_or_not") should append the string “free_or_not” to the first row of the apps_data list of lists.
    Note that apps_data[:1] is not the same as apps_data[1:]

  2. apps_data[0] is the short form of writing apps_data[:1] which means that they are the same, and this is the reason why the two lines of code return the same value which is the first row/header in the apps_data list of lists.

I hope this answers your questions.

1 Like