I have a function that returns 2 results, None
or dict
however I am trying to check if a key specifies this in the result of this function.
def get_language(card):
if not card.foreign_names == None:
for c in card.foreign_names:
if c['language'].lower().startswith('Portuguese'.lower()):
return c
return None
When the function returns a dict
I can easily check the key as follows:
result = get_language(card)
'my_key' in result
But if the function returns None
I get the following error:
TypeError: argument of type 'NoneType' is not iterable
This error is generated due to an attempt to compare using% inline%:
a = x if 'my_key' in result else None
On my computer I can perform this task even with if
but I do not have my notebook, does this have to do with the python version? and how can I resolve this?
Python 3.5.2