[Solved] Parsing txt using python sets data structure [closed]


You can open the file and get the lines as a string using:

with open("/path/to/file.txt") as file:
    lines = list(file)

This will give you a list of all lines in the text file.
Now since you do not want duplicates, I think using set would be a good way. (Set does not contain duplicates)

answer=set()
for x in lines:
   answer.add(x[x.find(" ")+1:x.rfind(":")])

This will iterate through all the lines and add the part after the space till and not including the : to the set, which will handle the case for duplicates. Now answer should contain all the unique urls

Tested for Python3.6

solved Parsing txt using python sets data structure [closed]