Python Nested Data Exercises Let’s check out some exercises that will help understand Nested Data better. Exercise 6-a Print 5 by accessing the nested data. nested_lst=[[1,2,3], [4,5,6], [7,8,9]] #Type your answer here. ans_1= print(ans_1) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(ans_1,nested_lst[1][1],"ans_1 checks") myTests().main() Hint 1 You can chain the bracket notation: [][][] to access the element you need. Solution ans_1 = nested_lst[1][1] Exercise 6-b Print "Z" from the nested data. nested_lst = [["Hat", "Glove", "Goggle"], ["Button", "Zipper", "Hook"]] #Type your code here. ans_1= print(ans_1) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(ans_1,nested_lst[1][1][0],"ans_1 checks") myTests().main() Hint 1 You can chain the bracket notation: [][][] to access the element you need. Solution ans_1 = nested_lst[1][1][0] Exercise 6-c What color is the violet? nested_lst = [{"orange": "orange"}, {"rose": "red"}, {"violet": "blue"}] #Type your code here. ans_1= print(ans_1) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(ans_1,nested_lst[2]["violet"],"ans_1 checks") myTests().main() Hint 1 You can chain the bracket notation: [][][] to access the element you need. Solution ans_1 = nested_lst[2]["violet"] Exercise 6-d Print the values of the "roads" key from the nested dictionary. nested_dict = {"Dakar":{"weather":"sunny", "roads":"dry"}} #Type your answer here. ans_1= print(ans_1) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(ans_1,nested_dict["Dakar"]["roads"],"ans_1 checks") myTests().main() Hint 1 If your dictionary’s key is a string you have to use quotes while accessing them.: [“string_key”] Solution ans_1 = nested_dict["Dakar"]["roads"] Exercise 6-e Print the first element of the weather for Tokyo. nested_dict = {"Tokyo": {"weather":["sunny", "cloudy"], "roads":"dry"}, "Dakar": {"weather":["foggy","windy"], "roads": "sandy"}} #Type your answer here. ans_1= print(ans_1) ==== from unittest.gui import TestCaseGui class myTests(TestCaseGui): def testOne(self): self.assertEqual(ans_1,nested_dict["Tokyo"]["weather"][0],"ans_1 checks") myTests().main() Hint 1 You can use a chain version of [][] notation with dictionary keys as well. Hint 2 If your dictionary’s key is a string you have to use quotes while accessing them.: [“string_key”] Solution ans_1 = nested_dict["Tokyo"]["weather"][0]