NLTK corpus: List down all the corpus names

NLTK corpus: Exercise-1 with Solution

Write a Python NLTK program to list down all the corpus names.

Sample Solution:

Python Code :

import nltk.corpus
print("\nAvailable corpus names:")

Sample Output:

Available corpus names:
['_LazyModule__lazymodule_globals', '_LazyModule__lazymodule_import', '_LazyModule__lazymodule_init', '_LazyModule__lazymodule_loaded', '_LazyModule__lazymodule_locals', '_LazyModule__lazymodule_name', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: NLTK Corpus Exercises Home.
Next: Write a Python NLTK program to get a list of common stop words in various languages in Python.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Share this Tutorial / Exercise on : Facebook and Twitter

Python: Tips of the Day

Get the Key Whose Value Is Maximal in a Dictionary:

>>> model_scores = {'model_a': 100, 'model_z': 198, 'model_t': 150}
>>> # workaround
>>> keys, values = list(model_scores.keys()), list(model_scores.values())
>>> keys[values.index(max(values))]
>>> # one-line
>>> max(model_scores, key=model_scores.get)