Home>
AAA
BBB
CCC
DDD
DDD
DDD
EEE
FFF
When there is such a file, DDD is continuous, so I want to delete the second and third DDD.
I know the strings written on successive lines.
AAA
BBB
CCC
DDD
EEE
FFF
path = file1
f = open (path)
line = f.readlines ()
f.close ()
for list in line:
with open (path) as f:
next (f)
for line2 in f
if line2 == list:
In this way, we tried to compare the first and n + 1 lines of the same file in order.
However, with this method, you have noticed that you cannot deal with the case where the same line continues more than once, and i am stuck.
Tell me how to do it well.
-
Answer # 1
Related articles
- python 3x - i want to delete duplicate lines
- python - [beginner] i want to delete line breaks/n after reading and outputting a file
- how to erase ruled lines in excel file using python
- python - i want to find the intersection of the lines of the least squares method when the button is pressed
- i want to delete a partially matching element in a python array
- python - how to break every 5 lines in the list
- python - how to delete an apostrophe in the list
- python - shuffle a few lines of dataframes together using pandas
- python scraping consecutive urls and saving as csv
- python - how can i place the grid lines of a bar chart behind the bars in matplotlib?
- python - delete bom on the command line
- python - how to delete vertices that meet the conditions in a graph using networkx
- i want to output multiple lines of html code using python
- about auxiliary lines and axis scales of python heatmap
- i want to delete a specific word from a string using a regular expression python
- python - i want to extract lines containing a specific string with pandas
- i want to read excel data with python and output duplicate lines as csv or excel data
- python3 extract and delete duplicate data of date and time
- [python] cannot insert or delete to text box
- how to extract lines that meet the conditions in a text file with python
Trends
It's an unknown code.
line
has already read the entire file, sofor list in line:
will look at each line.If it is the same as the previous line, do not output.
The previous line to be compared must be remembered in another variable in the previous loop.