I have a text file and I need to assign a random word from this text file (each word is on a separate line) to a variable in Python. Then I need to remove this word from the text file.
This is what I have so far.
with open("words.txt") as f: #Open the text file
wordlist = [x.rstrip() for x in f]
variable = random.sample(wordlist,1) #Assigning the random word
print(variable)