''' Purpose: demonstrate dict mappings ''' # get access to url support import url # where is the dog to notoriety mappings PUPPIES_CSV = "http://www.cs.virginia.edu/~cs1112/datasets/csv/puppies.csv" # get data set dataset = url.get_dataset( PUPPIES_CSV ) # convert dataset to a form suitable for querying # Let's create a dictionary of our dogs to their achievements! # Build a dictionary out of the dataset! (Dataset is a list of lists) notoriety = { } # Initialize an empty dict for row in dataset: # Go through each row in dataset and convert to a mapping k, v = row # Each row was a [dog, achievement] notoriety[ k ] = v # Create a mapping in our dictionary # dog : achievement ( k : v ) # ask for dog of interest reply = input( "Enter name of dog: " ) dog = reply.strip() dog = dog.capitalize() # look up claim to fame fame = notoriety.get( dog ) print( fame )