I currently have a function that takes each line of filename and adds each line to a list as its own element. However, I'd like to only be able to take the first num lines of the file. For example, if num = 2, the function only adds the first two lines of the file into the list. Here's what I have so far:
def storeFile(filename, num):
listOfLines = []
for line in open(filename, 'r').readlines():
listOfLines.append(line.strip())
return listOfLines
Any help would be appreciated!