NLTK: No value returned when searching the CMU dictionary based on syllable value
My bad, I realized the mistake. I had swapped the position of "pron" with "word" thereby causing this problem. The corrected code is:



p3 = [(pron[0] + '-' + pron[2], word)
            for word, pron in entries if pron[0] == 'P' and len(pron) == 3]
      "
I am practicing the nltk examples from the "Natural language processing in Python" book. While trying to get the words that start with syllable "p" and of syllable length 3 from cmu dictionary (one of the examples provided in chapter 2), I am not getting any values returned. I am using Python 3. Below is the code:



entries = nltk.corpus.cmudict.entries()
p3 = [(pron[0] + '-' + pron[2], word)
            for pron, word in entries if pron[0] == 'P' and len(pron) == 3]



But no value returned: 



p3 = 
      []



However, I know that the value exist. See below:



[(word, pron[0] + '-' + pron[2]) for word, pron in entries if word == 'perch']
[('perch', 'P-CH')]