2
I have a function that returns me 2 results, None
or dict
however I am trying to verify 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 a comparison attempt using a if
inline:
a = x if 'my_key' in result else None
On my computer I can accomplish this task even with None
but me my notebook no, this has to do with the python version? and how can I solve this?
Python 3.5.2
What’s the operation you’re trying to do next? when you make that mistake?
– Miguel
@Miguel I take the result and try to make a comparison with the
if
inline,a = x if 'my_key' in result else None
– RFL