Python Forum
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Word generator
#4
EDIT: I misunderstood you question. The word don't need a meaning? They can be some chars + one or more vowel?
In this case you should take a look into the module random. Look for choice.
Then you should look into string.ascii_lowercase or for more entropy into string.ascii_letters.
There is more than one way. First you can generate a list with 4 random chars from ascii_lowercase and check if after generation a vowel is inside. If not, repeat it.

Don't read it, if you won't do it with real words.

I you use this code, your teacher kills you :-D
If you use this code in a project, the other programmers will kill you.

with open('wordlist.txt') as infile, open('filtered_words.txt', 'w') as outfile:
   outfile.write('\n'.join(word for word in infile.read().splitlines() if len(word) == 4 and any(map(lambda v: v in word, 'aeiou'))))
used resource: http://www.ef.com/english-resources/engl...000-words/

First you should learn, how to open files.
Then learn about loops.
Read what the in operator does.
You need the len function to get the len of an element.
The code above won't help you to understand. It's just a silly joke.

What you have to do:
  • create an empty list
  • load a word list
  • iterate over the word list with a for loop
  • check the condition if a word has then length of 4
  • check if a vowel is in the word (with a second loop inside the loop), or read more about any, map, lambda
  • learn about the break statement in a while loop, for loop
  • if both conditions are fulfilled, append the word to the list

I think you need 3 days to learn the basics.
The code above is not basic and even hard to understand.

Use the newest Python version.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
Word generator - by jack1234 - Jul-02-2017, 02:58 PM
RE: Word generator - by buran - Jul-02-2017, 03:05 PM
RE: Word generator - by jack1234 - Jul-02-2017, 04:01 PM
RE: Word generator - by DeaD_EyE - Jul-02-2017, 04:40 PM
RE: Word generator - by Bass - Jul-02-2017, 04:44 PM
RE: Word generator - by buran - Jul-02-2017, 06:34 PM
RE: Word generator - by ichabod801 - Jul-02-2017, 08:48 PM
RE: Word generator - by DeaD_EyE - Jul-02-2017, 11:14 PM
RE: Word generator - by tozqo - Jul-03-2017, 03:07 AM
RE: Word generator - by DeaD_EyE - Jul-03-2017, 07:16 AM
RE: Word generator - by snippsat - Jul-03-2017, 09:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Generator: From Word to Numbers, from Numbers to n possibles Words Yamiyozx 2 1,493 Jan-02-2023, 05:08 PM
Last Post: deanhystad
  No output in 'english word generator' DeGerlash 14 6,617 Jan-10-2018, 12:23 PM
Last Post: squenson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020