Created
November 15, 2022 14:48
-
-
Save dippyshere/0eab2e5628e464c34a7805e37dcc162d to your computer and use it in GitHub Desktop.
convert txt list to py list without duplicates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Takes an input txt file with items separated by a newline and outputs a python list of the items without duplicates | |
# open txt file and convert to list | |
with open("input.txt") as f: | |
content = f.read().splitlines() | |
# remove duplicates | |
seen = set() | |
result = [] | |
for item in content: | |
if item not in seen: | |
seen.add(item) | |
result.append(item) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment