Python Forum
Not equal a dictionary key value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not equal a dictionary key value
#1
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?
Reply
#2
What is exactly wrong here?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  is there equal syntax to "dir /s /b" kucingkembar 2 988 Aug-16-2022, 08:26 AM
Last Post: kucingkembar
  Can a variable equal 2 things? Extra 4 1,500 Jan-18-2022, 09:21 PM
Last Post: Extra
  Misunderstanding with the “if” statement and “not equal” scriptoghost 6 4,432 Jun-23-2017, 09:43 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020