Lack of understanding

Screen Link:

My Code:

def open_dataset(file_name='AppleStore.csv', header=True):        
    opened_file = open(file_name)
    from csv import reader
    read_file = reader(opened_file)
    data = list(read_file)
    if header:
        return data[0], data[1:]
        return data
all_data = open_dataset()
header = all_data[0]
apps_data = all_data[1:]


What I expected to happen:

What actually happened:

apps_data is shorter than we expected.
header is longer than we expected.

Hello community,

the concept of Functions is so far clear to me. But i don’t understand the solution for this screen.

The first task is if header == true return separatly both the header and the rest of the data set.
Now if i write:

    if header:
        return data[0], data[1:]

It runs into an error because the [1:] is the determined as the first return element.

But why? For me it makes more sense to first return the header [0] and after that the entire data set[1:].
Is there a reason for this logic or is it “only” the setup of this screen?

If somebody can bring some light into the darkness it would be very appreiciated from my side. :slight_smile:

Regards and thanks,

Just the “setup” of this screen. If you interchange them in the return statement then you will have to make sure that you use the correct corresponding indices when creating header and apps_data.

I am assuming your return statement was the following (it’s different from the code you shared at the beginning of your post) to get the above message -

With the above, you will have to make sure that you use the correct indices when indexing the tuple all_data and storing the outcomes in header and apps_data.

header will not be all_data[0].

1 Like

Hi @the_doctor thanks for clarifying. I was not sure if it is only the setup of the screen but now it is clear for me. :slight_smile:

And yes you are right, I had a little copy & paste error at the beginning of my post.