The following is a code that I must complete. So, the result I want is to read through a file(every line) and if the first letter of the line that i read in the file matches with the letter that I have chosen returning the line in the list matches.
def lines_startswith(file,letter):
'''(file open for reading, str) -> list of str
Return the list of lines from file that begin with letter. The lines should have the newline removed.
Precondition:len(letter) == 1
'''
matches = []
(blank)
return matches
I have to fill in the (blank) to complete the code.
This is what I have so far but I haven't been able to get the result that I needed.
for line in file:
if line[0] == 'letter':
matches.append(line)
What is wrong with my code?