Skip to content

Instantly share code, notes, and snippets.

@bilhox
Created February 26, 2024 14:54
Show Gist options
  • Save bilhox/4fe92002d7f01f3985e00e8c47827f25 to your computer and use it in GitHub Desktop.
Save bilhox/4fe92002d7f01f3985e00e8c47827f25 to your computer and use it in GitHub Desktop.
Récupère le texte du fichier passé en argument lors de l'exécution, et crée un fichier avec tout les mots utilisés sans doublon.
import sys
text = ""
ponctuation = ['?', '...', '..', '.', ':', '"', "'", '!', ';', ',', '/', '&']
with open(sys.argv[1], mode='r', newline='') as reader:
for line in reader.readlines():
for c in line.strip():
if c not in ponctuation:
text += c
words = set([w.strip().lower() for w in text.split()])
with open("result.txt", mode="w") as writer:
for word in words:
writer.write(word + "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment