Answer the following questions along with Python code and its result. Make sure
ID: 3355629 • Letter: A
Question
Answer the following questions along with Python code and its result. Make sure to import NLTK and all of books.
1. Find all words in the Chat Corpus (text5) starting with the letter b. Show them in alphabetical order without duplication (to get vocabulary).
2. Find all the four-letter words in the Chat Corpus (text5). With the help of a frequency distribution (FreqDist), show the first 10 words in decreasing order of frequency.
3. Write expressions for finding all words in text6 that meet the following conditions.
The result should be in the form of a list of words: ['word1', 'word2', ...]. (4 pts – 1 pt each)
1) Ending in ize
2) Containing the letter z
3) Containing the sequence of letters pt
4) All lowercase letters except for an initial capital (i.e., titlecase)
4. What does the following Python code do?
>>> sum([len(w) for w in text1])
What does the number of summation means?
Explanation / Answer
1) Answer:
sorted(set([i for i in text5 if i.startswith('b')]))
or
sorted(set([i for i in text5 if i and i[0] == 'b']))
2)Answer:
fours = set([w for w in text5 if len(w) == 4])
The above finds all the four-letter words.
f = FreqDist(text5)
reversed_pairs = [(v, k) for k, v in f.items()]
list(reversed(sorted(reversed_pairs)))
The above help to get words in decreasing order of frequency.
3)
1. Ending in ize
Answer:
In [1]: [w for w in text6 if len(w) > 4 and w[-3:] == ('ize')]
Out[1]: []
2. Containing the letter z
Answer:
In [1]: list(set([w for w in text6 if w.lower().find('z') != -1]))
Out[1]:
['zhiv',
'zone',
'frozen',
'amazes',
'zoo',
'zoop',
'zoosh',
'AMAZING',
'ZOOT',
'Zoot',
'Fetchez']
3. Containing the sequence of letters pt
Answer:
In [1]: list(set([w for w in text6 if w.lower().find('pt') != -1]))
Out[1]:
['Chapter',
'temptress',
'temptation',
'excepting',
'Thppt',
'Thppppt',
'Thpppt',
'ptoo',
'Thpppppt',
'aptly',
'empty']
4. All lowercase letters except for an initial capital (i.e., titlecase)
Answer:
list(set([w for w in text6 if w[0].isupper() and w[1:].islower()]))
4) >>> sum([len(w) for w in text1])
Answer: It returns the sum total of the lengths of all "words" in text1.
summation means the process of adding things together, the process of summing something up. Often mathematical formulae require the addition of many variables Summation or sigma notation is a convenient and simple form of shorthand used to give a concise expression for a sum of the values of a variable.
Please rate
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.