Screen Link:
https://app.dataquest.io/c/112/m/316/functions%3A-intermediate/6/returning-multiple-variables
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:]
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.
Regards and thanks,
Simo