V
V
vasiklas2021-06-19 21:10:41
Python
vasiklas, 2021-06-19 21:10:41

I want to know with the help of a loop in python'e whether there are matches in the file. txt?

I have a problem. There are a lot of links in the file, and I want to find out if there are identical links in the file through a loop in python. txt, so if there are identical links, I will have an error in other code. https://pastebin.com/9sbTu89C here is an example of how I tried to solve this problem, but obviously I wrote something wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2021-06-19
@andrey_u

with open('test.html', 'r') as file:
    urls = sorted([u.strip() for u in file.readlines()])

urls_duplicate = sorted(list(set([u for u in urls if urls.count(u) > 1])))
print(urls_duplicate)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question