Generate Python code to fetch an item from a dictionary based on a given key.
dictionary = {
"name": "John",
"age": 40
}
key = "name"
dictionary = {
"name": "John",
"age": 40
}
key = "name"

for key, value in dictionary.items():
  if key == key:
    print(value)
    break