def traverse_dict_and_list(data, key, default, delimiter=DEFAULT_TARGET_DELIM):
 for each in key.split(delimiter):
  if isinstance(data, list):
   try:
    idx = int(each)
   except ValueError:
    embed_match = False
    for embedded in (x for x in data if isinstance(x, dict)):
     try:
      data = embedded[each]
      embed_match = True
      break
     except KeyError:
      pass
    if (not embed_match):
     return default
   else:
    try:
     data = data[idx]
    except IndexError:
     return default
  else:
   try:
    data = data[each]
   except (KeyError, TypeError):
    return default
 return data

def traverse_dict_and_list ( data , key , default , delimiter = DEFAULT_TARGET_DELIM ) : for each in key . split ( delimiter ) : if isinstance ( data , list ) : try : idx = int ( each ) except ValueError : embed_match = False for embedded in ( x for x in data if isinstance ( x , dict ) ) : try : data = embedded [ each ] embed_match = True break except KeyError : pass if ( not embed_match ) : return default else : try : data = data [ idx ] except IndexError : return default else : try : data = data [ each ] except ( KeyError , TypeError ) : return default return data
traverse a dict or list using a colon-delimited target string .