Exercise 49. Making Sentences

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

Exercise 49 Python Session

Python 3.6.0 (default, Feb  2 2017, 12:48:29)[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> from ex48 import lexicon>>> lexicon.scan("go north")[('verb', 'go'), ('direction', 'north')]>>> lexicon.scan("kill the princess")[('verb', 'kill'), ('stop', 'the'), ('noun', 'princess')]>>> lexicon.scan("eat the bear")[('verb', 'eat'), ('stop', 'the'), ('noun', 'bear')]

This will also work on longer sentences such as lexicon.scan("open the door and smack the bear in the nose") ...

Get Learn Python 3 the Hard Way: A Very Simple Introduction to the Terrifyingly Beautiful World of Computers and Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.