def menu_clean(menu_config):
    """
    Make sure that only the menu item with the largest weight is active.
    If a child of a menu item is active, the parent should be active too.
    :param menu:
    :return:
    """
    max_weight = -1
    for _, value in list(menu_config.items()):
        if value["submenu"]:
            for _, v in list(value["submenu"].items()):
                if v["active"]:
                    # parent inherits the weight of the axctive child
                    value["active"] = True
                    value["active_weight"] = v["active_weight"]

        if value["active"]:
            max_weight = max(value["active_weight"], max_weight)

    if max_weight > 0:
        # one of the items is active: make items with lesser weight inactive
        for _, value in list(menu_config.items()):
            if value["active"] and value["active_weight"] < max_weight:
                value["active"] = False
    return menu_config
def menu_clean ( menu_config ) : max_weight = - 1 for _ , value in list ( menu_config . items ( ) ) : if value [ "submenu" ] : for _ , v in list ( value [ "submenu" ] . items ( ) ) : if v [ "active" ] : value [ "active" ] = True value [ "active_weight" ] = v [ "active_weight" ] if value [ "active" ] : max_weight = max ( value [ "active_weight" ] , max_weight ) if max_weight > 0 : for _ , value in list ( menu_config . items ( ) ) : if value [ "active" ] and value [ "active_weight" ] < max_weight : value [ "active" ] = False return menu_config
Make sure that only the menu item with the largest weight is active.
    If a child of a menu item is active, the parent should be active too.
    :param menu:
    :return: