Mad Libs is a word game that starts from a quote or a short story where some keywords have been replaced with blanks. A lexical or other category is specified underneath each blank, such as "noun", "verb", "place", or "part of the body". One player then asks the other players, in turn, to suggest a word for the category specified under the next blank, but without revealing the context for that word. Finally, the filled quote or the completed story is read aloud. The result is usually comic, surreal and somewhat nonsensical.

Say we start for example from the following partial quote.

______ created _______ so that __________ would learn ____________.
 Name           thing           CITIZENS               discipline

The missing words could be completed as follows

God created war so that AMERICANS would learn geography.

or equally well in the following way

Mercator created maps so that BELGIANS would learn navigation.

The game was invented by Leonard Stern en Roger Price, and more than 110 million copies of the Mad Libs books have been sold in the US alone since the series was first published in 1958.

mad libs book#1 mad libs book#2 mad libs book#3 mad libs book#4 mad libs book#5 mad libs book#6

Assignment

Write a class MadLibs whose objects can be used to complete a given quote or story in which some keywords have been replaced with blanks, by randomly picking words from the indicated categories. Each object of this class must have a vocabulary property that is a reference to a dictionary (dict). This dictionary represents the vocabulary the object has learned so far. Initially the dictionary is empty, but new information can be added throughout the object's lifetime, or the information in the dictionary can be consulted by calling the following methods that must be supported by the class MadLibs:

Example

>>> madlib = MadLibs()
>>> madlib.vocabulary
{}

>>> madlib.learn('name', 'God')
>>> madlib.learn('thing', 'war')
>>> madlib.learn('citizens', 'Americans')
>>> madlib.learn('discipline', 'geography')
>>> madlib.vocabulary
{'discipline': {'geography'}, 'thing': {'war'}, 'citizens': {'americans'}, 'name': {'god'}}
>>> madlib.suggest('name')
'god'
>>> madlib.suggest('NAME')
'GOD'
>>> madlib.suggest('Name')
'God'
>>> madlib.fill('_Name_ created _thing_ so that _CITIZENS_ would learn _discipline_.')
'God created war so that AMERICANS would learn geography.'

>>> madlib.learn('name', ('Mercator', 'Caesar'))
>>> madlib.learn('thing', ['maps', 'coordinates'])
>>> madlib.learn('citizens', {'Belgians', 'Martians', 'Germans'})
>>> madlib.learn('discipline', 'navigation')
>>> madlib.learn('discipline', 'colonisation')
>>> madlib.vocabulary
{'discipline': {'colonisation', 'navigation', 'geography'}, 'thing': {'maps', 'war', 'coordinates'}, 'citizens': {'belgians', 'americans', 'germans', 'martians'}, 'name': {'god', 'caesar', 'mercator'}}
>>> madlib.fill('_Name_ created _thing_ so that _CITIZENS_ would learn _discipline_.')
'Mercator created maps so that BELGIANS would learn geography.'
>>> madlib.fill('_Name_ created _thing_ so that _CITIZENS_ would learn _discipline_.')
'Mercator created war so that BELGIANS would learn navigation.'

>>> madlib.suggest('country')
Traceback (most recent call last):
AssertionError: unknown category

>>> madlib.suggest('_CITIZENS_ live in _Country_.')
Traceback (most recent call last):
AssertionError: unknown category