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
Then you should look into
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.
First you should learn, how to open files.
Then learn about loops.
Read what the
You need the
The code above won't help you to understand. It's just a silly joke.
What you have to do:
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.
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 afor 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!
All humans together. We don't need politicians!