Answers for "function to open file and give random word from file python"

1

choice random word in python from a text file

import random
print(random.choice(open('file.txt').read().split()).strip())
Posted by: Guest on October-19-2020
1

how to get random word from text file in python

import random
def importword(): # finding a random word in the dictionary
    file = open("wdd.txt", "r")
    for x in range(0,random.randint(0,466909)):
        word = file.readline(x)
    return word
Posted by: Guest on October-09-2021

Code answers related to "function to open file and give random word from file python"

Python Answers by Framework

Browse Popular Code Answers by Language