How to get all the hyponyms of a word/synset in python nltk and wordnet?

Solution 1:

from nltk.corpus import wordnet as wn
vehicle = wn.synset('vehicle.n.01')
typesOfVehicles = list(set([w for s in vehicle.closure(lambda s:s.hyponyms()) for w in s.lemma_names()]))

This will give you all the unique words from every synset that is a hyponym of the noun "vehicle" (1st sense).

Solution 2:

def get_hyponyms(synset):
    hyponyms = set()
    for hyponym in synset.hyponyms():
        hyponyms |= set(get_hyponyms(hyponym))
    return hyponyms | set(synset.hyponyms())