Skip to content

Instantly share code, notes, and snippets.

@dippyshere
Created November 15, 2022 14:48
Show Gist options
  • Save dippyshere/0eab2e5628e464c34a7805e37dcc162d to your computer and use it in GitHub Desktop.
Save dippyshere/0eab2e5628e464c34a7805e37dcc162d to your computer and use it in GitHub Desktop.
convert txt list to py list without duplicates
# 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