''' Purpose: demonstrate while loop and 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 # accumulator notoriety = { } for row in dataset : name, fame = row # each row has two entries notoriety[ name ] = fame # want add a new entry that associates current name to current fame; # not append because there is no order for dicts ( append adds to end) #print ( notoriety ) order might be different for your print; dictionaries are unordered # ask for dog of interest print( notoriety ) print() reply = input( 'Enter name of dog: ' ) dog = reply.strip() #dog = dog.capitalize() # look up claim to fame fame = notoriety.get( dog ) print( fame ) # Dictionaries: # In real life dicts you look up words to find their meanings. # In CS dicts you look up keys to find their values fame = input( 'Enter description of dog: ' ) for name in notoriety: if notoriety[name] == fame: print( name ) # Note: values can be lists