human
Complete this python program:
def flat_user_answer(user_answer):
assistant
#Here is the Python code you requested.

    """Convert nested `user_answer` to flat format.
    {\up\: {\first\: {\p\: \p_l\}}}
    to
    {\up\: \p_l[p][first]\}
    """
    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