subject

Python code:

write a function create_dictionary(filename) that takes a string representing the name of a text file, and that returns a dictionary of key-value pairs in which:

1) each key is a word encountered in the tex file

2) the corresponding value is a list of words that follow the key word in the text file

for example the dictionary produced the text "i love roses and carnations. i hope i get roses for my birthday." would include the following key-value pairs, among others:

'i': ['love', 'hope', 'get']
'love': ['roses']
'roses': ['and', 'for']
'my': ['birthday.']
# as well as others!
guidelines:

-you should not try to remove the punctuation from the words of the text file.

-the keys of the dictionary should include every word in the file except the sentence-ending words. a sentence-ending word is defined to be any word whose last character is a period ('.'), a question mark ('? '), or an exclamation point ('! '). a sentence-ending word should be included in the lists associated with the words that it follows (i. e., in the value parts of the appropriate key-value pairs), but it not appear as its own key.
-if a word w1 is followed by another word w2 multiple times in the text file, then w2should appear multiple times in the list of words associated with w1. this will allow you to capture the frequency with which word combinations appear.
-in addition to the words in the file, the dictionary should include the string $ as a special key referred to as the sentence-start symbol. this symbol will be used when choosing the first word in a sentence. in the dictionary, the list of words associated with the key '$' should include:
the first word in the file
every word in the file that follows a sentence-ending word.
-doing this will ensure that the list of words associated with '$' includes all of the words that start a sentence. for example, the dictionary for the text "i scream. you scream. we all scream for ice cream." would include the following entry for the sentence-start symbol:
'$': ['i', 'you', 'we']
-you may find it to consult the word_frequencies function from class. we will also discuss some additional strategies for create_dictionary in class.
examples:
to test your code, download the sample. txt file into the same directory that containsps13pr4.py. this sample text file contains the following contents:
a b a. a b c. b a c. c c c.
once this file is in place, run your ps13pr4.py in idle and test your function from the shell:
> > > word_dict = create_dictionary('sample. txt')
> > > word_dict
{'a': ['b', 'b', 'c.'], 'c': ['c', 'c.'],
'b': ['a.', 'c.', 'a'], '$': ['a', 'a', 'b', 'c']}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 00:00
Sam is a data analyst at an advertising firm. he often uses a spreadsheet that contains media ratings details. he would like to filter the spreadsheet data based on different filter criteria. which operators can he use to specify the combination of filter criteria? sam can use the ( blank ) operators to specify a combination of filter criteria.
Answers: 3
question
Computers and Technology, 22.06.2019 02:00
Consider how gaming consoles initially relied on joysticks and joypads and then made the switch to modern gaming controls, which include analog sticks, buttons and switches, touch controls, accelerometers, motion controls, etc. name at least two kinds of gaming experiences that are possible with these new control devices but were not possible on original joysticks. explain how new technologies made this newer game style possible.
Answers: 1
question
Computers and Technology, 22.06.2019 07:30
In the film "epic 2015," epic is the name for:
Answers: 3
question
Computers and Technology, 23.06.2019 16:30
Monica and her team have implemented is successfully in an organization. what factor leads to successful is implementation? good between different departments in an organization leads to successful is implementation.
Answers: 1
You know the right answer?
Python code:

write a function create_dictionary(filename) that takes a string represent...
Questions
Questions on the website: 13722367