Python -- find all the keys used in the inner dictionary and return them as a collection.

'''
3. Write a name db_headings The function of requires to be able to find all the keys used in the inner dictionary and return them in the form of a set.
//Take the dictionary given as an example. The function should return the set {'author', 'forename', 'born', 'surname', 'notes',' did '}.


{
    'jgoodall':{'surname':'goodall',
                'forename':'Jane',
                'born':1934,
                'died':None,
                'notes':'primate researcher',
                'author':['In the Shadow of Man','The Chimpanzees of Gombe']},
    'rfranklin':{'surname':'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 Sporing']}
    }
'''
def db_headings():
    people = {
    'jgoodall':{'surname':'goodall',
                'forename':'Jane',
                'born':1934,
                'died':None,
                'notes':'primate researcher',
                'author':['In the Shadow of Man','The Chimpanzees of Gombe']},
    'rfranklin':{'surname':'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 Sporing']}
    }
    l=[]
    for name in people.values():
        a = name
        for name in a.keys():
            l.append(name)
    n=[]
    for i in l:
        if i not in n:
             n.append(i)
    print(n)
db_headings()



'''
#Create one to store a student's information, and all the information can be retrieved through traversal
student={'name':'xiaoming','age':11,'school':'tsinghua'}
for key,value in student.items():
    print(key+':'+str(value))

//Output: 
age:11 
name:xiaoming 
school:tsinghua
//Be careful: 
//The output order of the traversed return value is different from that of the storage, and the output order will change every time 
//In the for loop, the key and value variables need to be separated by a comma ','


#Key fetch
student = {'name': 'xiaoming', 'age': 11, 'school': 'tsinghua'}
    for name in student.keys():
        print(name)
//output   
name
age
school


#The order of the values returned by keys() is uncertain. If you want to sort them in order, you can use sorted()
for name in sorted(people.keys()):
'''

More dry goods are coming, please look forward to

PS: This article is first published in the public number "let me meet a similar soul", reply to keywords to get dozens of programmers classic ebooks.

Left hand code, right hand guitar, this is the world: if one day I meet a similar soul, it must be hard to walk and not be understood. Let me touch it if I can
It's just as lonely for too long Different literary youth, different procedural apes.

Posted by spadmore on Sat, 23 Nov 2019 13:07:02 -0800