(Jul-03-2017, 03:07 AM)tozqo Wrote: DeaD_EyE, what's wrong with your sample code? Is it because you are opening a word list instead of generating a word?
My code was the wrong answer and is not readable for beginners.
from functools import partial def with_vowel(word, word_len): # hint: strip newline when comparing the size return len(word.strip()) == word_len and any(map(lambda vowel: vowel in word, 'aeiou')) # trying to do it memory efficient and readable def filter_text(infilename, outfilename, condition): with open(infilename) as infile, open(outfilename, 'w') as outfile: for word in infile: # for loop iterates over lines if the file was opened in text mode # word has a newline character inside if condition(word): outfile.write(word) with_vowel_len4 = partial(with_vowel, word_len=4) with_vowel_len5 = partial(with_vowel, word_len=5) filter_text('wordlist.txt', 'filtered_words.txt', with_vowel_len4) filter_text('wordlist.txt', 'filtered_words_len5.txt', with_vowel_len5)But this was not the task. Additionally there are modules in pip for password generation if needed.
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!