Next Post:
Previous Post:

In PHP, there is the check for empty array elements using the empty() function. In Python there is no such one function and the same can be accomplished by a rather elegant try-catch block:

try:
iso_language_code = tweet['iso_language_code']
except KeyError:
iso_language_code = ‘zz’
try:
    new_var = array_var['element_name']
except KeyError:
    new_var = 'default_value'  # or None

I will say it is neat.