Exercise 1: Word tokenization with NLTK
Here, you'll be using the first scene of Monty Python's Holy Grail, which has been pre-loaded as scene_one. Feel free to check it out in the IPython Shell!
Your job in this exercise is to utilize word_tokenize and sent_tokenize from nltk.tokenize to tokenize both words and sentences from Python strings - in this case, the first scene of Monty Python's Holy Grail.
Instruction
- Import the
sent_tokenizeandword_tokenizefunctions fromnltk.tokenize. - Tokenize all the sentences in
scene_oneusing thesent_tokenize()function. - Tokenize the fourth sentence in
sentences, which you can access assentences[3], using theword_tokenize()function. - Find the unique tokens in the entire scene by using
word_tokenize()onscene_oneand then converting it into a set usingset(). - Print the unique tokens found. This has been done for you, so hit 'Submit Answer' to see the results!
Hints
- Use the command
from y import xto importxfromy. - Use the
sent_tokenize()function to tokenize the sentences inscene_one. - Use
word_tokenize()to tokenize the appropriate sentence insentences. Remember, Python uses 0-based numbering. - After using
word_tokenize()onscene_one, use theset()function to convert it into a set.

Last modified: Sunday, 11 June 2023, 11:49 AM