Reputation: 99
I have a list comprehension like this : view['entries'] = [entry for entry in view['entries'] if qs in entry.get('name') or qs in entry.get('description')]
This list comprehension is a search filter that works with the name field because it's a required field that is never empty.
But when I search for description, I got the error TypeError: argument of type 'NoneType' is not iterable
Description field can be empty.
Upvotes: 1
Views: 164
Reputation: 73450
If in doubt, you can always just provide an empty string default value:
if qs in entry.get('name', '') or qs in entry.get('description', ''):
If the keys can be actually present with value None
, you can do:
if qs in (entry.get('name') or '') or qs in (entry.get('description') or ''):
Upvotes: 2