I'm reading a file and putting contents into dictionary. I'm writing a method where I search for key and return its value. How do I throw exception if my key is not present in dictionary. For example below is the code I'm testing but I get output of re.search as None for non-match items. Can I use has_key() method?
mylist = {'fruit':'apple','vegi':'carrot'}
for key,value in mylist.items():
    found = re.search('vegi',key)
    if found is None:
       print("Not found")
       else:
       print("Found")
Found Not found
 
     
     
    