1lines_seen = set() # holds lines already seen
2
3with open("file.txt", "r+") as f:
4 d = f.readlines()
5 f.seek(0)
6 for i in d:
7 if i not in lines_seen:
8 f.write(i)
9 lines_seen.add(i)
10 f.truncate()
1with open("file.txt", "r") as txt_file:
2 new_data = list(set(txt_file))
3 return new_data