O'Reilly logo

Learn Python the Hard Way: A Very Simple Introduction to the Terrifyingly Beautiful World of Computers and Code, Third Edition, Video-Enhanced Edition by Zed A. Shaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercise 49. Making Sentences

ImageVideo: Exercise 49: Making Sentences

What we should be able to get from our little game lexicon scanner is a list that looks like this:

    >>> from ex48 import lexicon    >>> print lexicon.scan("go north")    [('verb', 'go'), ('direction', 'north')]    >>> print lexicon.scan("kill the princess")    [('verb', 'kill'), ('stop', 'the'), ('noun', 'princess')]    >>> print lexicon.scan("eat the bear")    [('verb', 'eat'), ('stop', 'the'), ('noun', 'bear')]    >>> print lexicon.scan("open the door and smack the bear in the nose")    [('error', 'open'), ('stop', 'the'), ('noun', 'door'), ('error', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required