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
It's an unknown code.
linehas already read the entire file, so
for 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.
- python - i want to delete all lines that contain a pandas string
- python3 extract and delete duplicate data of date and time
- python - i want to extract only the matching lines in two csv and output a new csv
- python - if you delete one of the records, how to delete the records in the other related tables
- exclude even and odd lines in python csv
- read a python text file and get n lines from the line starting with the specified string
- is there a way to safely delete the cache generated by a python program while the program is running?
- python - i want to delete the rest of the django migration history
- python - when combining different lines for each mode, switching the mode will change the whole
- python - draw a specified number of straight lines at equal intervals
- i want to make sure to delete /pyenv/shims/python
- python - i want to delete a remote repository
- [python/pandas] how to delete columns with 1 element at once
- python delete files after uploading
- python - i want to delete all the images (* jpg) on my drive
- python - i want to extract lines containing a specific string with pandas
- [python] cannot insert or delete to text box
- i want to delete a specific word from a string using a regular expression python
- about auxiliary lines and axis scales of python heatmap
- i want to output multiple lines of html code using python
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- python - you may need to restart the kernel to use updated packages error
- python 3x - typeerror: 'method' object is not subscriptable
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- android studio - unresolved reference comes out in kotlin