def flat_user_answer(user_answer):
 def parse_user_answer(answer):
  key = answer.keys()[0]
  value = answer.values()[0]
  if isinstance(value, dict):
   complex_value_list = []
   v_value = value
   while isinstance(v_value, dict):
    v_key = v_value.keys()[0]
    v_value = v_value.values()[0]
    complex_value_list.append(v_key)
   complex_value = '{0}'.format(v_value)
   for i in reversed(complex_value_list):
    complex_value = '{0}[{1}]'.format(complex_value, i)
   res = {key: complex_value}
   return res
  else:
   return answer
 result = []
 for answer in user_answer:
  parse_answer = parse_user_answer(answer)
  result.append(parse_answer)
 return result

def flat_user_answer ( user_answer ) : def parse_user_answer ( answer ) : key = answer . keys ( ) [ 0 ] value = answer . values ( ) [ 0 ] if isinstance ( value , dict ) : complex_value_list = [ ] v_value = value while isinstance ( v_value , dict ) : v_key = v_value . keys ( ) [ 0 ] v_value = v_value . values ( ) [ 0 ] complex_value_list . append ( v_key ) complex_value = '{0}' . format ( v_value ) for i in reversed ( complex_value_list ) : complex_value = '{0}[{1}]' . format ( complex_value , i ) res = { key : complex_value } return res else : return answer result = [ ] for answer in user_answer : parse_answer = parse_user_answer ( answer ) result . append ( parse_answer ) return result
convert nested user_answer to flat format .