how can i randomly print an element from a list in python
- by lm
So far i have this, which prints out every word in my list, but i am trying to print only one word at random. Any suggestions?
def main():
# open a file
wordsf = open('words.txt', 'r')
word=random.choice('wordsf')
words_count=0
for line in wordsf:
word= line.rstrip('\n')
print(word)
words_count+=1
# close the file
wordsf.close()