A Less Practical Solution for Introduction to Python, Functions: Intermediate - Step 6/12

The code below (while still functional) is less practical because the header variable, created at the very bottom, requires calling two index numbers instead of one to bring up the header row.

SOLUTION 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[1:], data
else:
    return data

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

hi @donniegoode

The if block return two arguments one with all rows other than the header, and one with the header only. So there is no need for double indexing while assigning value to the variable header.

image

it is missing over here, I don’t understand why :frowning:
image

1 Like

I know, just thought to share an alternative way of solving the same problem. The given solution code (or your code) is 100% more concise and easier to work with. Thanks for the input though! :smile:

1 Like