Python小练习

        3.15. Make a multilevel dictionary called life. Use these strings for the topmost keys: 'animals', 'plants', and 'other'. Make the

'animals' key refer to another dictionary with the keys 'cats', 'octopi', and 'emus'. Make the 'cats' key refer to a list of strings

with the values 'Henri', 'Grumpy', and 'Lucy'. Make all the other keys refer to empty dictionaries.

       3.16. Print the top-level keys of life.

       3.17. Print the keys for life['animals'].

       3.18. Print the values for life['animals']['cats'].

life = { 'animals' : { 'cats' : [ 'Henri', 'Grumpy', 'Lucy' ], 'octopi' : {}, 'emus' : {}  }, 'plants' : {}, 'other' : {} }
print(life.keys())
life['animals']
life['animals']['cats']

 

图1 程序运行结果

 

系统:Ubuntu 16.04 LTS

Python:3.7

你可能感兴趣的:(Python,Linux学习)