the goog stock was already in the dictionaryso when we tried to setdefault it to an invalid valueit just returned the value already in the dictionary bbry was not in the dictionaryso setdefault returned the default value and set the new value in the dictionary for us we then check that the new stock isindeedin the dictionary three other very useful dictionary methods are keys()values()and items(the first two return an iterator over all the keys and all the values in the dictionary we can use these like lists or in for loops if we want to process all the keys or values the items(method is probably the most usefulit returns an iterator over tuples of (keyvaluepairs for every item in the dictionary this works great with tuple unpacking in for loop to loop over associated keys and values this example does just that to print each stock in the dictionary with its current valuefor stockvalues in stocks items()print("{last value is {}format(stockvalues[ ])goog last value is bbry last value is msft last value is each key/value tuple is unpacked into two variables named stock and values (we could use any variable names we wantedbut these both seem appropriateand then printed in formatted string notice that the stocks do not show up in the same order in which they were inserted dictionariesdue to the efficient algorithm (known as hashingthat is used to make key lookup so fastare inherently unsorted sothere are numerous ways to retrieve data from dictionary once it has been instantiatedwe can use square brackets as index syntaxthe get methodthe setdefault methodor iterate over the items methodamong others finallyas you likely already knowwe can set value in dictionary using the same indexing syntax we use to retrieve valuestocks["goog"( stocks['goog'( google' price is lower todayso 've updated the tuple value in the dictionary we can use this index syntax to set value for any keyregardless of whether the key is in the dictionary if it is in the dictionarythe old value will be replaced with the new oneotherwisea new key/value pair will be created