Create explanation (as a list of header/content entries) for an answer

def get_explanation(logical_form: str,
                    world_extractions: JsonDict,
                    answer_index: int,
                    world: QuarelWorld) -> List[JsonDict]:
    """
    Create explanation (as a list of header/content entries) for an answer
    """
    output = []
    nl_world = {}
    if world_extractions['world1'] != "N/A" and world_extractions['world1'] != ["N/A"]:
        nl_world['world1'] = nl_world_string(world_extractions['world1'])
        nl_world['world2'] = nl_world_string(world_extractions['world2'])
        output.append({
                "header": "Identified two worlds",
                "content": [f'''world1 = {nl_world['world1']}''',
                            f'''world2 = {nl_world['world2']}''']
        })
    else:
        nl_world['world1'] = 'world1'
        nl_world['world2'] = 'world2'
    parse = semparse_util.lisp_to_nested_expression(logical_form)
    if parse[0] != "infer":
        return None
    setup = parse[1]
    output.append({
            "header": "The question is stating",
            "content": nl_arg(setup, nl_world)
    })
    answers = parse[2:]
    output.append({
            "header": "The answer options are stating",
            "content": ["A: " + " and ".join(nl_arg(answers[0], nl_world)),
                        "B: " + " and ".join(nl_arg(answers[1], nl_world))]
    })
    setup_core = setup
    if setup[0] == 'and':
        setup_core = setup[1]
    s_attr = setup_core[0]
    s_dir = world.qr_size[setup_core[1]]
    s_world = nl_world[setup_core[2]]
    a_attr = answers[answer_index][0]
    qr_dir = world._get_qr_coeff(strip_entity_type(s_attr), strip_entity_type(a_attr))  # pylint: disable=protected-access
    a_dir = s_dir * qr_dir
    a_world = nl_world[answers[answer_index][2]]

    content = [f'When {nl_attr(s_attr)} is {nl_dir(s_dir)} ' +
               f'then {nl_attr(a_attr)} is {nl_dir(a_dir)} (for {s_world})']
    if a_world != s_world:
        content.append(f'''Therefore {nl_attr(a_attr)} is {nl_dir(-a_dir)} for {a_world}''')
    content.append(f"Therefore {chr(65+answer_index)} is the correct answer")

    output.append({
            "header": "Theory used",
            "content": content
    })

    return output