If running in the main lesson Notebook:¶
oldfile = open("sortedfriends.txt", "r")
contents = oldfile.readlines()
N = len(contents)
with open("backwardsfriends.txt", "w") as newfile:
for i in range(-1, -N, -1):
newfile.write(contents[i])
If running in the solutions notebook:¶
need to refer to the folder above the
solutions
folder using the../
syntax:
oldfile = open("../sortedfriends.txt", "r")
contents = oldfile.readlines()
N = len(contents)
with open("backwardsfriends.txt", "w") as newfile:
for i in range(-1, -N, -1):
newfile.write(contents[i])