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

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:

data=f.readlines()

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

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

d={}

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

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

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

temp={}

for jin range(1,7):

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

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

s1=""

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

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

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

else:

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

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

this is the problem :

This is the question that i am doing for practice, i have

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 "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' , "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.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!