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:

  data=f.readlines()

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()[0]=='scientist'):

      temp={}

      for j in 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 :Screen Shot 2019-10-01 at 10.44.22 AM.png

Screen Shot 2019-10-01 at 10.44.22 AM.png

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.)

Recently Asked Questions

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
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes