love2code love2code - 8 months ago 12
Python Question

Why comparing empty values is not working?

I have a list of dictionaries.

students = [{"id":''},{"id":1},{"id":3}]

I am iterating through this and looking for dictionaries where id is not

Here is what I have tried:

for student in students:
if(student['id'] is not None or student['id'] != ''):
print("found student" + str(student['id']))

But no matter what, it always goes inside the
block. Any pointers what is wrong in comparing blank values?


What about:

if student['id'] not in (None, ''):
    # do someting