Reading file through split function

Screen Link:
https://app.dataquest.io/c/77/m/422/lists-and-for-loops/8/from-strings-to-lists

My Code:

opened_file = open('AppleStore.csv')
read_file = opened_file.read()
new_line_split = read_file.split("\n")
print(new_line_split)

header = new_line_split[0]
print(header)

What I expected to happen:
i am expecting the new_line_split to be list of list, since as per the article i am able to assign header = new_line_split[0].

What actually happened:
new_line_Split is displayed as a single list

Replace this line with the output/error

The content already clarifies this for us -

The split() command returned a list. Looking at its first five elements, we see that each element of the list corresponds to one line of the text file

When we use split(), we get a list in which each element is a row from the text file.

so is ā€˜/nā€™ the same as whitespace?

Hey, Michel.

Whitespace refers to multiple characters, two examples are \n (the newline character) and Ā  (the space character).

1 Like