""" Purpose: introduce the dict type """ # initialize dictionary and print it out flora_to_color = { 'spruce': 'green', 'apple': 'red', 'shamrock': 'green', 'banana': 'yellow', 'potato': 'brown', 'eggplant': 'purple' } print( "flora_to_color: ", flora_to_color ) print(); input( "Enter when ready. " ); print() # determine number of mappings nbr_mappings = len( flora_to_color ) print( "len( flora_to_color): ", nbr_mappings ) print(); input( "Enter when ready. " ); print() # access individual dictionary entry c1 = flora_to_color[ 'potato' ] print( "flora_to_color[ 'potato' ]: )", c1 ) print(); input( "Enter when ready. " ); print() # add mapping to dictionary flora_to_color[ 'lemon' ] = 'yellow' print( "flora_to_color: ", flora_to_color ) print(); input( "Enter when ready. " ); print() # reset dictionary mapping flora_to_color[ 'potato' ] = 'golden' print( "flora_to_color: ", flora_to_color ) print(); input( "Enter when ready. " ); print() # get the keys and values of the dictionary flora_keys = flora_to_color.keys() color_values = flora_to_color.values() print( "flora_to_color.keys(): ", flora_keys ) print( "flora_to_color.values(): ", color_values ) print(); input( "Enter when ready. " ); print() # convert keys and values to lists flora = list( flora_keys ) colors = list( color_values ) print( "list( flora_to_color.keys() ): ", flora ) print( "list( flora_to_color.values() ): ", colors ) print(); input( "Enter when ready. " ); print() # loop through the mappings for key in flora_to_color: value = flora_to_color[ key ] print( key, ":", value )