readlines replace n 1

readlines replace \n

with open(filename) as f:
    mylist = f.read().splitlines() 

Here is what the above code is Doing:
1. We open the file and read it into a variable called f.
2. We then use the .read() method to read the entire contents of the file into a variable called contents.
3. We then use the .splitlines() method to split the contents into a list of lines.
4. We then assign the list of lines to a variable called mylist.

Similar Posts