Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Complete the function parse _ file ( ) . This function takes a file name as a parameter, reads the file line by line and
Complete the function parsefile This function takes a file name as a parameter, reads the file line by line and creates a data structure to represent the input. The structure has the following format: at the top it is a pair. The first element of the pair is a list of names the participants in the order given in the file. The second element of the pair is a list of pairs; each list cell will correspond to a given day. Within each listpair, the first element should be a dictionary whose keys are the names of those tested for vampirism and whose values are the Booleans True that is a vampire, indicated by V in the input file or False that is a human The second element of a listpair is a list of lists, with each outer listelement being an inner list of those groups who were in contact on that day. After you finish processing the file, make sure to close it and then return the structure youve created. Heres the structure wed expect for the sample file given above, as printed by Python: Bella 'Edward', 'Jacob', 'Carlisle', 'Alice', 'Emmett', 'Charlie', 'Renee', 'Jessica', 'Angela'Edward: True, 'Bella': False, 'Jacob': False, 'Jessica': FalseBella 'Edward'Charlie 'Jacob' Alice 'Renee'Bella: False, 'Jacob': False, 'Alice': True, 'Charlie': FalseBella 'Edward', 'Charlie'Angela 'Jessica' Emmett: True, 'Renee': False, 'Jessica': TrueBella: True, 'Charlie': FalseBella 'Edward', 'Charlie', 'Jessica', 'Angela' Jacob 'Renee' If the file isnt somehow formatted correctly for example, if one of the numbers isnt a number when you convert it to an integer then print the error message
Complete the function parsefile This function takes a file name as a parameter, reads the file line by line and
creates a data structure to represent the input. The structure has the following format: at the top it is a pair. The
first element of the pair is a list of names the participants in the order given in the file. The second element of the
pair is a list of pairs; each list cell will correspond to a given day.
Within each listpair, the first element should be a dictionary whose keys are the names of those tested for vampirism
and whose values are the Booleans True that is a vampire, indicated by V in the input file or False that is a
human The second element of a listpair is a list of lists, with each outer listelement being an inner list of those
groups who were in contact on that day. After you finish processing the file, make sure to close it and then return
the structure youve created. Heres the structure wed expect for the sample file given above, as printed by Python:
Bella 'Edward', 'Jacob', 'Carlisle', 'Alice', 'Emmett', 'Charlie',
'Renee', 'Jessica', 'Angela'Edward: True, 'Bella': False, 'Jacob':
False, 'Jessica': FalseBella 'Edward'Charlie 'Jacob'
Alice 'Renee'Bella: False, 'Jacob': False, 'Alice': True,
'Charlie': FalseBella 'Edward', 'Charlie'Angela 'Jessica'
Emmett: True, 'Renee': False, 'Jessica': TrueBella: True,
'Charlie': FalseBella 'Edward', 'Charlie', 'Jessica', 'Angela'
Jacob
'Renee'
If the file isnt somehow formatted correctly for example, if one of the numbers isnt a number when you convert it
to an integer then print the error message
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started