View the step-by-step solution to:

Question

This is the question that i am doing for practice, i have taken a crack at it but i cant seem to get any further

than i am. could you show me how to finish it ?

this is what i have done

with open("dic_db_scientists.txt") as f:

for i in range(0,len(data)):

data[i]=data[i].strip('n')

d={}

for i in range(0,len(data)):

if(data[i]!=''):

if(data[i].split()=='scientist'):

temp={}

for j in range(1,7):

if(data[i+j]!=''):

if(data[i+j].split()!='author'):

s1=""

for k in range(1,len(data[i+j].split())):

s1=s1+data[i+j].split()[k]+" "

temp[data[i+j].split()] = s1

else:

temp[data[i+j].split()] = data[i+j].strip('author ').split(', ')

d[data[i].split()]=temp

this is the problem :  3. (30) Dictionary of dictionaries can be used as a simple database. For instance, dictionary in Figure 2 can be
used for tracking information about scientists.
db_dic = {
'jgoodall '
: { ' surname'
'Goodall' ,
forename
&quot;Jane' ,
born
: 1934
'died'
: None,
notes'
'primate researcher' ,
' author'
'rfranklin' : {' surname'
['In the Shadow of Man' , 'The Chimpanzees of Gombe' ]},
'Franklin',
forename'
'Rosalind' ,
born
1920
died
1957,
notes
contributed to discovery of DNA' },
rcarson'
: { surname
Carson' ,
'forename'
'Rachel' ,
&quot;born'
1907
died
1964
'notes'
'raised awareness of effects of DDT' ,
author'
: [ 'Silent Spring' ] }
Figure 2: A dictionary of dictionary example
Assume that the data is provided as a text file (see dic_db scientists.txt). First, you need to read and save
the data as a dictionary of dictionaries as shown in Figure 2. Note that first value in each line is a key, and
the rest is the value. If there are multiple values to be stored, these values are separated by comma (as in the
case for author key of jgoodall). Next, answer the following questions:
(a) Write a python function called db headings that returns the set of keys used in any of the inner diction
naries. In the example in Figure 2, the function should return
set ('author , forename' ,' surname' ;' notes',' born' ;' died')
(b) Write another function called db_consistent that takes a dictionary of dictionaries in the format de-
scribed in the previous question and returns True if and only if every one of the inner dictionaries has
exactly the same keys. (This function would return False for the previous example, since Rosalind
Franklin's entry does not contain the 'author' key.)

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
• -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents