Count all the lines that begin with the character 'A' or 'E' in a file and write it to another file. python
Answers
Answered by
0
Count all the lines that begin with the character 'A' or 'E' in a file and write it to another file using Python
Explanation:
# Opening a file
file = open("gfg.txt","r")
Counter = 0
# Reading from file
Content = file.read()
CoList = Content.split("\n")
for i in CoList:
if line.startswith("A"):
Counter += 1
file= open("new.txt", "w");
content= file.write(counter);
elif if line.startswith("E"):
Counter += 1
file= open("new.txt", "w");
content= file.write(counter);
print("This is the number of lines starting with A or E in the file")
print(Counter)
Similar questions