0

How to manage the following:

listing = db.query("SELECT list_id FROM results limit 10")

returns a list containing values converted to long type : ({'list_id': 175L},...)

element = db.query("SELECT * FROM list LIMIT 1")

returns returns a single element which has a standard int id : element['id'] = 175

Now i would like to do something like this:

if element['id'] not in listing:
   print "ok"

But the loop is never entered. I think it is because of the different types in the list (long) and element (int).

Is there a quick and simple solution to solve this problem?

Thanks

J-H
  • 1,795
  • 6
  • 22
  • 41

1 Answers1

0

Your first query returns list of dictionaries. You are trying to find a value in dictionary. Here is correct way how to iterate through keys in a dictionary:

for name, age in list.iteritems():
    if age == search_age:
        print name

Taken from here: Get key by value in dictionary

Community
  • 1
  • 1
user1209304
  • 408
  • 1
  • 5
  • 26