Returning Multiple Variables

data Quest 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:]
else:
    return data

all_data = open_dataset()

header = all_data[1]
apps_data = all_data[0]

==========================
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:]
else:
    return data

all_data = open_dataset()
header = all_data[0]
apps_data = all_data[1]

I want to inform the website about this mistake

1 Like

Thank you for posting the correction on the last part.
Could explain why app_data=all_data[1] returns the rest of the data set? I was under the impression that app_data=all_data[1:] would have worked

2 Likes

Because what yoy said was already settled in the function itself “open_dataset()”, so just when set a new variable I will to call the 2nd index from tje function, also I didn’t try data[1:] but I guess it won’t differ as it is just the rest of the function starting from 1 which is in this csse is only 1
But I didn’t try it actually, anyways this is why it is data[1] from my side

I have just finished Functions: Intermediate and I was confused by the answer to the code referenced about. I found that since the header is index 0 and the assignment states extract the header then… its best to assign the header first. The same way that @ayahdemerdash did it. Additionally the rationale (swapping) that was used in the DQ answer is not explained until the next lesson.