Try using the Python interpreter as a calculator, and typing expressions like 12 / (4 + 1).
In [1]:
12/(4+1)
Out[1]:
Given an alphabet of 26 letters, there are 26 to the power 10, or 26 ** 10, ten-letter strings we can form. That works out to 141167095653376L (the L at the end just indicates that this is Python's long-number format). How many hundred-letter strings are possible?
In [2]:
26 ** 100
Out[2]:
The Python multiplication operation can be applied to lists. What happens when you type ['Monty', 'Python'] 20, or 3 sent1? Answer: The list item(s) gets multiplied to N number of times. Where N is an integer.
In [3]:
['Monty', 'Python'] * 20
Out[3]:
In [4]:
sent1 = ['Call', 'me', 'Ishmael', '.']
3 * sent1
Out[4]:
Review 1.1 on computing with language. How many words are there in text2? How many distinct words are there?
In [3]:
import nltk
nltk.download()
Out[3]:
In [5]:
from nltk.book import *
In [6]:
print 'There are %d distict words in text2'%(len(set(text2)))
Find the collocations in text5.
In [7]:
text5.collocations()
Consider the following Python expression: len(set(text4)). State the purpose of this expression. Describe the two steps involved in performing this computation.
It computes length of unique words in text4. The first is set operation which removes duplicates and second is calculating length of unique words.
In [8]:
len(set(text4))
Out[8]:
In [ ]: