Random Word in Dictionary [closed]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















How might I get a python function to, every time it is called, pick a random five-letter word from the English dictionary?










share|improve this question















closed as too broad by juanpa.arrivillaga, arshajii, Prune, jpp, MarianD Nov 16 '18 at 23:48


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 2





    What have you tried so far?

    – Danoram
    Nov 16 '18 at 23:20











  • Could this be of any use? github.com/dwyl/english-words

    – lgwilliams
    Nov 16 '18 at 23:21






  • 1





    Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. On topic, how to ask, and ... the perfect question apply here. StackOverflow is not a design, coding, research, or tutorial resource. However, if you follow whatever resources you find on line, make an honest coding attempt, and run into a problem, you'd have a good example to post.

    – Prune
    Nov 16 '18 at 23:23











  • It would load an english language from some source, then probably use the random library to select a word from that text corpus

    – G. Anderson
    Nov 16 '18 at 23:25


















0















How might I get a python function to, every time it is called, pick a random five-letter word from the English dictionary?










share|improve this question















closed as too broad by juanpa.arrivillaga, arshajii, Prune, jpp, MarianD Nov 16 '18 at 23:48


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 2





    What have you tried so far?

    – Danoram
    Nov 16 '18 at 23:20











  • Could this be of any use? github.com/dwyl/english-words

    – lgwilliams
    Nov 16 '18 at 23:21






  • 1





    Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. On topic, how to ask, and ... the perfect question apply here. StackOverflow is not a design, coding, research, or tutorial resource. However, if you follow whatever resources you find on line, make an honest coding attempt, and run into a problem, you'd have a good example to post.

    – Prune
    Nov 16 '18 at 23:23











  • It would load an english language from some source, then probably use the random library to select a word from that text corpus

    – G. Anderson
    Nov 16 '18 at 23:25














0












0








0








How might I get a python function to, every time it is called, pick a random five-letter word from the English dictionary?










share|improve this question
















How might I get a python function to, every time it is called, pick a random five-letter word from the English dictionary?







python string python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 23:23









Prune

46.1k143759




46.1k143759










asked Nov 16 '18 at 23:18









skwarerütskwarerüt

1185




1185




closed as too broad by juanpa.arrivillaga, arshajii, Prune, jpp, MarianD Nov 16 '18 at 23:48


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as too broad by juanpa.arrivillaga, arshajii, Prune, jpp, MarianD Nov 16 '18 at 23:48


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 2





    What have you tried so far?

    – Danoram
    Nov 16 '18 at 23:20











  • Could this be of any use? github.com/dwyl/english-words

    – lgwilliams
    Nov 16 '18 at 23:21






  • 1





    Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. On topic, how to ask, and ... the perfect question apply here. StackOverflow is not a design, coding, research, or tutorial resource. However, if you follow whatever resources you find on line, make an honest coding attempt, and run into a problem, you'd have a good example to post.

    – Prune
    Nov 16 '18 at 23:23











  • It would load an english language from some source, then probably use the random library to select a word from that text corpus

    – G. Anderson
    Nov 16 '18 at 23:25














  • 2





    What have you tried so far?

    – Danoram
    Nov 16 '18 at 23:20











  • Could this be of any use? github.com/dwyl/english-words

    – lgwilliams
    Nov 16 '18 at 23:21






  • 1





    Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. On topic, how to ask, and ... the perfect question apply here. StackOverflow is not a design, coding, research, or tutorial resource. However, if you follow whatever resources you find on line, make an honest coding attempt, and run into a problem, you'd have a good example to post.

    – Prune
    Nov 16 '18 at 23:23











  • It would load an english language from some source, then probably use the random library to select a word from that text corpus

    – G. Anderson
    Nov 16 '18 at 23:25








2




2





What have you tried so far?

– Danoram
Nov 16 '18 at 23:20





What have you tried so far?

– Danoram
Nov 16 '18 at 23:20













Could this be of any use? github.com/dwyl/english-words

– lgwilliams
Nov 16 '18 at 23:21





Could this be of any use? github.com/dwyl/english-words

– lgwilliams
Nov 16 '18 at 23:21




1




1





Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. On topic, how to ask, and ... the perfect question apply here. StackOverflow is not a design, coding, research, or tutorial resource. However, if you follow whatever resources you find on line, make an honest coding attempt, and run into a problem, you'd have a good example to post.

– Prune
Nov 16 '18 at 23:23





Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. On topic, how to ask, and ... the perfect question apply here. StackOverflow is not a design, coding, research, or tutorial resource. However, if you follow whatever resources you find on line, make an honest coding attempt, and run into a problem, you'd have a good example to post.

– Prune
Nov 16 '18 at 23:23













It would load an english language from some source, then probably use the random library to select a word from that text corpus

– G. Anderson
Nov 16 '18 at 23:25





It would load an english language from some source, then probably use the random library to select a word from that text corpus

– G. Anderson
Nov 16 '18 at 23:25












2 Answers
2






active

oldest

votes


















4














You can use nltk's corpus along with random.sample:



>>> from nltk import words
>>> import random
>>> print(random.sample(words.words(), 5))
[u'myectopia', u'hinch', u'venation', u'toeboard', u'pennet']


Edit



To get a random five letter word:



>>> five_letter_words = [w for w in words.words() if len(w) == 5]
>>> print(random.choice(five_letter_words))
gaudy





share|improve this answer





















  • 1





    While NLTK requires installation, I think that this is the cleanest answer.

    – lgwilliams
    Nov 16 '18 at 23:34



















0














Let's assume you have stored all your English words in a file words.txt. Then you can read them in like so:



myWords = 
with open("words.txt", "r") as inF:
for line in inF:
line = line.strip()
if line == "": continue
myWords.append(line)


in order to reduce the list so that only those words of length 5 are left, you can use the filter function:



myWordsOf5Chars = list(filter(lambda x : len(x) == 5, myWords))


and then, afterwards, you can use



from random import choice
print(choice(myWordsOf5Chars))


in order to pick a random word from this list and output it.






share|improve this answer






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    You can use nltk's corpus along with random.sample:



    >>> from nltk import words
    >>> import random
    >>> print(random.sample(words.words(), 5))
    [u'myectopia', u'hinch', u'venation', u'toeboard', u'pennet']


    Edit



    To get a random five letter word:



    >>> five_letter_words = [w for w in words.words() if len(w) == 5]
    >>> print(random.choice(five_letter_words))
    gaudy





    share|improve this answer





















    • 1





      While NLTK requires installation, I think that this is the cleanest answer.

      – lgwilliams
      Nov 16 '18 at 23:34
















    4














    You can use nltk's corpus along with random.sample:



    >>> from nltk import words
    >>> import random
    >>> print(random.sample(words.words(), 5))
    [u'myectopia', u'hinch', u'venation', u'toeboard', u'pennet']


    Edit



    To get a random five letter word:



    >>> five_letter_words = [w for w in words.words() if len(w) == 5]
    >>> print(random.choice(five_letter_words))
    gaudy





    share|improve this answer





















    • 1





      While NLTK requires installation, I think that this is the cleanest answer.

      – lgwilliams
      Nov 16 '18 at 23:34














    4












    4








    4







    You can use nltk's corpus along with random.sample:



    >>> from nltk import words
    >>> import random
    >>> print(random.sample(words.words(), 5))
    [u'myectopia', u'hinch', u'venation', u'toeboard', u'pennet']


    Edit



    To get a random five letter word:



    >>> five_letter_words = [w for w in words.words() if len(w) == 5]
    >>> print(random.choice(five_letter_words))
    gaudy





    share|improve this answer















    You can use nltk's corpus along with random.sample:



    >>> from nltk import words
    >>> import random
    >>> print(random.sample(words.words(), 5))
    [u'myectopia', u'hinch', u'venation', u'toeboard', u'pennet']


    Edit



    To get a random five letter word:



    >>> five_letter_words = [w for w in words.words() if len(w) == 5]
    >>> print(random.choice(five_letter_words))
    gaudy






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 16 '18 at 23:36

























    answered Nov 16 '18 at 23:29









    sliderslider

    8,56811331




    8,56811331








    • 1





      While NLTK requires installation, I think that this is the cleanest answer.

      – lgwilliams
      Nov 16 '18 at 23:34














    • 1





      While NLTK requires installation, I think that this is the cleanest answer.

      – lgwilliams
      Nov 16 '18 at 23:34








    1




    1





    While NLTK requires installation, I think that this is the cleanest answer.

    – lgwilliams
    Nov 16 '18 at 23:34





    While NLTK requires installation, I think that this is the cleanest answer.

    – lgwilliams
    Nov 16 '18 at 23:34













    0














    Let's assume you have stored all your English words in a file words.txt. Then you can read them in like so:



    myWords = 
    with open("words.txt", "r") as inF:
    for line in inF:
    line = line.strip()
    if line == "": continue
    myWords.append(line)


    in order to reduce the list so that only those words of length 5 are left, you can use the filter function:



    myWordsOf5Chars = list(filter(lambda x : len(x) == 5, myWords))


    and then, afterwards, you can use



    from random import choice
    print(choice(myWordsOf5Chars))


    in order to pick a random word from this list and output it.






    share|improve this answer




























      0














      Let's assume you have stored all your English words in a file words.txt. Then you can read them in like so:



      myWords = 
      with open("words.txt", "r") as inF:
      for line in inF:
      line = line.strip()
      if line == "": continue
      myWords.append(line)


      in order to reduce the list so that only those words of length 5 are left, you can use the filter function:



      myWordsOf5Chars = list(filter(lambda x : len(x) == 5, myWords))


      and then, afterwards, you can use



      from random import choice
      print(choice(myWordsOf5Chars))


      in order to pick a random word from this list and output it.






      share|improve this answer


























        0












        0








        0







        Let's assume you have stored all your English words in a file words.txt. Then you can read them in like so:



        myWords = 
        with open("words.txt", "r") as inF:
        for line in inF:
        line = line.strip()
        if line == "": continue
        myWords.append(line)


        in order to reduce the list so that only those words of length 5 are left, you can use the filter function:



        myWordsOf5Chars = list(filter(lambda x : len(x) == 5, myWords))


        and then, afterwards, you can use



        from random import choice
        print(choice(myWordsOf5Chars))


        in order to pick a random word from this list and output it.






        share|improve this answer













        Let's assume you have stored all your English words in a file words.txt. Then you can read them in like so:



        myWords = 
        with open("words.txt", "r") as inF:
        for line in inF:
        line = line.strip()
        if line == "": continue
        myWords.append(line)


        in order to reduce the list so that only those words of length 5 are left, you can use the filter function:



        myWordsOf5Chars = list(filter(lambda x : len(x) == 5, myWords))


        and then, afterwards, you can use



        from random import choice
        print(choice(myWordsOf5Chars))


        in order to pick a random word from this list and output it.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 23:27









        quantquant

        1,60711527




        1,60711527















            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine