I'm trying to create a list on python from a text file saved in my documents. The list contains the 1000 most commonly used words in the english dictionary, with each word on a new line in the text file.
When I tried doing:
wordlist = []
with open("C:\\Users\\Myname\\Documents\\words.txt") as file:
for line in file:
wordlist.append(line)
print(wordlist)
The result I got was:
['the\n', 'of\n', 'to\n', 'and\n', 'a\n', 'in\n', 'is\n', 'it\n', 'you\n', 'that\n', 'he\n', 'was\n', 'for\n', 'on\n', 'are\n'....etc.]
I would like each element/word in the list to be without the quotation marks and the \n.
The second part to my question is how can I choose a random word from either that created list in python, or from the .txt file directly (in fact I'd like to learn how to do both) and save it to a variable?
Edit: also, how can I choose a random word over a certain number of characters from either that created list in python, or from the .txt file directly
I am running the latest version of python