1. [20 points] Create a file with name “hw2_FIRST_LAST.py” and download
“nasdaq.txt” , “raven.txt” , “frankenstein” files into the same directory where your
“hw2_FIRST_LAST.py” code is located.
2. [20 points] In “hw2_FIRST_LAST.py” file, define a function make_length_wordcount()
that:
a. Takes input as the filename in the current directory (as a string)
b. Returns a dictionary, which each key is word length and its value is the number of words
with that length.
i. Words should be translated to lowercase.
ii. For example, if the input file’s text is “Hello Python people Welcome to the
world of Python”, then the dictionary should be:
{2: 2, 3: 1, 5: 2, 6: 3, 7: 1}
3. [20 points] In “hw2_FIRST_LAST.py” file, define a function make_word_count() that:
a. Takes input as the filename in the current directory (as a string)
b. Returns a dictionary, which each key is a word and its value is the number of
occurrences of that word.
i. Words should be translated to lowercase.
ii. For example, if the input file’s text is “Hello Python people Welcome to the
world of Python”, then the dictionary should be:
{'hello': 1, 'of': 1, 'people': 1, 'python': 2, 'the': 1, 'to':
1, 'welcome': 1, 'world': 1}
4. [20 points] In “hw2_FIRST_LAST.py” file, define a function analyze_text() that:
a. Takes input as the filename in the current directory (as a string)
b. Uses the two functions above – make_length_wordcount() and
make_word_count() - to construct (i) length-wordcount dictionary and (ii) word count
dictionary.
c. Opens a new output file “FILE_analyzed_FIRST_LAST.txt” and write two
dictionaries into this file (in the format below).
d. For example, if the input file is “test.txt”, the output file name is
“test_analyzed_HYUN_KANG.txt” and it should contain the following lines:
Words of length 2 : 2
Words of length 3 : 1
Words of length 5 : 2
Words of length 6 : 3
Words of length 7 : 1to : 1
of : 1
people : 1
the : 1
python : 2
welcome : 1
hello : 1
world : 1
5. [20 points] In “hw2_FIRST_LAST.py” file, run the analyze_text() function three times
with the following inputs:
a. “nasdaq.txt”
b. “raven.txt”
c. “frankenstein.txt”
Your hw2.py code should generate the following three files:
“nasdaq_analyzed_FIRST_LAST.txt”
“raven_analyzed_FIRST_LAST.txt” “frankenstein_analyzed_FIRST_LAST.txt”
Please check test.txt and test_analyzed_FIRST_LAST.txt to check the expected
오카로드림여
오카가 먼데
3마넌 주면 해준다 ^^