def dict_to_keyval(value, key_base=None):
 (val_iter, key_func) = (None, None)
 if isinstance(value, dict):
  val_iter = six.iteritems(value)
  key_func = (lambda k: (((key_base + '.') + k) if key_base else k))
 elif isinstance(value, (tuple, list)):
  val_iter = enumerate(value)
  key_func = (lambda k: (key_base + ('[%d]' % k)))
 if val_iter:
  for (k, v) in val_iter:
   key_gen = key_func(k)
   if (isinstance(v, dict) or isinstance(v, (tuple, list))):
    for (key_gen, v) in dict_to_keyval(v, key_gen):
     (yield (key_gen, v))
   else:
    (yield (key_gen, v))

def dict_to_keyval ( value , key_base = None ) : ( val_iter , key_func ) = ( None , None ) if isinstance ( value , dict ) : val_iter = six . iteritems ( value ) key_func = ( lambda k : ( ( ( key_base + '.' ) + k ) if key_base else k ) ) elif isinstance ( value , ( tuple , list ) ) : val_iter = enumerate ( value ) key_func = ( lambda k : ( key_base + ( '[%d]' % k ) ) ) if val_iter : for ( k , v ) in val_iter : key_gen = key_func ( k ) if ( isinstance ( v , dict ) or isinstance ( v , ( tuple , list ) ) ) : for ( key_gen , v ) in dict_to_keyval ( v , key_gen ) : ( yield ( key_gen , v ) ) else : ( yield ( key_gen , v ) )
expand a given dict to its corresponding key-value pairs .