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

Why is the category free or not at the end?

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

My Code:

Replace this line with your code
```# 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
    if price == 0:
        app.append('free')
    else:
        app.append('non-free')
        
apps_data[0].append('free_or_not')

print(apps_data)

What I expected to happen:


What actually happened: 

``` The label column-label 'free_or_not' is at the end of Output.
Replace this line with the output/error

[‘id’, ‘track_name’, ‘size_bytes’, ‘currency’, ‘price’, ‘rating_count_tot’, ‘rating_count_ver’, ‘user_rating’, ‘user_rating_ver’, ‘ver’, ‘cont_rating’, ‘prime_genre’, ‘sup_devices.num’, ‘ipadSc_urls.num’, ‘lang.num’, ‘vpp_lic’, ‘free_or_not’]

I expected the label ‘free_or_not’ to be at the first position of the list, because i appended it to the element zero: apps_data[0].append(‘free_or_not’). How is this possible? It’s not logical for me. Maybe somebody can give me some deeper explanation. It don’t want to ignore this only because my code works because i think it’s fundamental to understand what happens here :). Thanks.

1 Like

apps_data is list of list. So what you did is

Added 'free_or_not' string at last position of first list of app_data

And More append method of list always add item at end of the list. There is insert method to add item at specific position

1 Like

Hi Dishin,

thanks i understand. You mean the first list of lists has only the headers and i added at the last position of the headers ‘free_or_not’ and because i added the other elements with the labels at the last element it fits? header at last position -> label from apps at last position?

Sorry if i’m wrong :slight_smile:

1 Like

@Simo Yes that is right.

Got it now, thanks :slight_smile: