ftoe['bois''woodprint translate('je bois du vin rouge 'dicts'french to english'will print wood of wine red we add elements to dictionary by assigning value to an unused keye ftoe['blanc''whiteas with liststhere are many useful methodsincluding some for removing elementsassociated with dictionaries we do not enumerate them herebut will use them as convenient in examples later in the book figure contains some of the more useful operations on dictionaries len(dreturns the number of items in keys(returns list containing the keys in values(returns list containing the values in in returns true if key is in [kreturns the item in with key get(kvreturns [kif is in dand otherwise [kv associates the value with the key in if there is already value associated with kthat value is replaced del [kremoves the key from for in iterates over the keys in figure some common operations on dicts objects of any immutable typee type tuplemay be used as dictionary keys imagine for example using tuple of the form (flightnumberdayto represent airline flights it would then be easy to use such tuples as keys in dictionary implementing mapping from flights to arrival times most programming languages do not contain built-in type that provides mapping from keys to values insteadprogrammers use other types to provide similar functionality it isfor examplerelatively easy to implement dictionary using list in which each element is key/value pair one can then write simple function that does the associative retrievale def keysearch(lk)for elem in lif elem[ =kreturn elem[ return none the problem with such an implementation is that it is computationally inefficient in the worst casea program might have to examine each element in the list to perform single retrieval in contrastthe built-in implementation is quite fast it uses technique called hashingdescribed in to do the lookup in time that is nearly independent of the size of the dictionary