0

So I have been trying to play around with keys and values where I then figured out I want to do a sort of contais.

I am using different json values that contains numbers of:

{'60': {'databaseurl': 'hello/world', 'name': 'Apple'}}

{'104': {'databaseurl': 'hello/world', 'name': 'Orange'}, '65': {'databaseurl': 'hello/world', 'name': 'Banana'}}

{'104': {'databaseurl': 'hello/world', 'name': 'Orange'}, '65': {'databaseurl': 'hello/world', 'name': 'Banana'}}

{'104': {'databaseurl': 'hello/world', 'name': 'Orange'}, '65': {'databaseurl': 'hello/world', 'name': 'Banana'}}

{'46': {'databaseurl': 'hello/world', 'name': 'Nuts'}}

{'81': {'databaseurl': 'hello/world', 'name': 'Nuts'}, '46': {'databaseurl': 'hello/world', 'name': 'Nuts'}}

and as you can see there is value of key such as 60, 104, 65, 46 and 81.

My wish is to be able to print out only the 46 and 81 numbers

What I tried to do is:

for i in resp.json().values():
    if i['numberssaved'] == 81 or 46:
        print(i['numberssaved'])

but that just prints out all of these numbers (Which is at the beginning of this thread) which I dont want.

My output that I want is that it should only printout everyone that contains only number of 81 and 46!

What did I do wrong with the code that it doesn't get only numbers 46 and 81?

The differene between the suggestion answer is not the same because in this issue it contains key and values where I want to check if the keys contains the numbers then continue the script else just pass.

Andres123
  • 7
  • 1
  • 7

1 Answers1

0

if i['numberssaved'] == 81 or 46: will not work because 46 will always evaluate to true, you want if i['numberssaved'] == 81 or i['numberssaved'] == 46:

Ben
  • 380
  • 1
  • 9
  • Hmm. It just gave me empty syntax. It didn't caught any. Could it be due to key? – Andres123 Oct 25 '18 at 11:11
  • It's unclear from the question what ```i``` and ```numberssaved``` are, so I'm not sure where the issue is. The only clear issue I could see in the original post was how the comparison was done, a more comprehensive response on that topic is addressed here: https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value – Ben Oct 25 '18 at 11:26