Q:

Printing only the value of a key in a dictionary

I would like further explanation as to why the following code prints the value of the key.  I am learning Python for a class and Zybooks is terrible at explaining.
# Complete the function to return a dictionary value
# if it exists or return Not Found if it doesn't exist
def findDictItem(mydict, key):
# Student code goes here
    if key in mydict:
        return (mydict[key])
    else:
        return 'Not Found'
# expected output: yellow
print(findDictItem({'tomato': 'red', 'banana': 'yellow', 'lime': 'green'} , 'banana'))
# expected output: Not Found
print(findDictItem({'Brazil': 'Brasilia', 'Ireland': 'Dublin', 'Indonesia': 'Jakarta'},'Cameroon'))

The return(mydict[key]), in my understanding, should return the key not the value, but returns they value instead.
Would someone please provide clarity?

A:

Remember that a dictionary is a map of keys to values, like
{
   'Ireland':   'Dublin',
   'Indonesia': 'Jakarta'
#   ^key         ^value
}

mydict[key] returns the value of the dictionary at index key. If you want the value of the dict at a certain key, you would use mydict[key], so mydict['Ireland'] will return Dublin.
If you just want to return Dublin, you would use return key

