Answered step by step
Verified Expert Solution
Link Copied!

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 parse_file(). 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 list-pair, 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 list-pair is a list of lists, with each outer list-element 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': False},[['Bella', 'Edward'],['Charlie', 'Jacob'],
['Alice', 'Renee']]),({'Bella': False, 'Jacob': False, 'Alice': True,
'Charlie': False},[['Bella', 'Edward', 'Charlie'],['Angela', 'Jessica']]),
({'Emmett': True, 'Renee': False, 'Jessica': True},[]),({'Bella': True,
'Charlie': False},[['Bella', '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

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions