Result is not Displayed
Peter Otten
__peter__ at web.de
Tue Nov 22 03:55:17 EST 2016
prihantoro2001 at gmail.com wrote:
> Dear all,
>
> i am new to Python and have this problem
>
> =====
> import nltk
> puzzle_letters = nltk.FreqDist('egivrvonl')
> obligatory = 'r'
> wordlist = nltk.corpus.words.words()
> [w for w in wordlist if len(w) >= 6
> and obligatory in w
> and nltk.FreqDist(w) <= puzzle_letters]
> print puzzle_letters
> ======
>
> this gives me <FreqDist with 8 samples and 9 outcomes>
> while the expected outcome is ['glover', 'govern', ...]
> did i miss something?
You asked for letters when you wanted to see the words. You actually build
the list of words with
> [w for w in wordlist if len(w) >= 6
> and obligatory in w
> and nltk.FreqDist(w) <= puzzle_letters]
but don't even bind it to a name. Try
words = [
w for w in wordlist if len(w) >= 6
and obligatory in w
and nltk.FreqDist(w) <= puzzle_letters
]
print words
to get what you want.
More information about the Python-list
mailing list