Python Forum

Full Version: Not equal a dictionary key value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have the follow code that works fine

 if 'bad' == computer_dictionary['threats']:
            get_threats(computers_url, computer_dictionary['id'])
but I want to do

 if 'good' != computer_dictionary['threats']:
            get_threats(computers_url, computer_dictionary['id'])
I don't do not equal to. What have I done wrong here?
What is exactly wrong here?
Actually it does work. The issue turns out to be that in some cases the key value is blank. I need to check that threats has a value. I am getting a KeyError: 'threats'. I thought it was due to the !=. I will work on this. Thanks for the reply though. It made me look at it again.