I have a dictionary item. It has strings as keys and the values are lists e.g.:
item['title'] = [u'python']
item['image'] = [u'/link/to/image']
item['link'] = [u'link to article']
I want to check if any value is 0 in length, but link or image may be empty, so I did the following:
for key, value in item.iteritems():
if len(value) == 0:
if key != 'image' or key != 'link':
raise DropItem("Item is empty: %s" %item)
return item
So an item should be dropped only if the value is 0 and it is not an image or a key. My problem is now that this condition does not work. The item is still dropped when the image or link is empty.
Any idea whats wrong? (I am new to python^^)
You confused the logical
orwithand. For example, if the key is"image", you check the following:Instead, you want
or, easier to read: