def _extract_and_flatten_nested_structure(data, flattened=None):
if flattened is None:<EOL><INDENT>flattened = []<EOL>structure = _extract_and_flatten_nested_structure(data, flattened)<EOL>return structure, flattened<EOL><DEDENT>if isinstance(data, list):<EOL><INDENT>return list(_extract_and_flatten_nested_structure(x, flattened) for x in data)<EOL><DEDENT>elif isinstance(data, tuple):<EOL><INDENT>return tuple(_extract_and_flatten_nested_structure(x, flattened) for x in data)<EOL><DEDENT>elif isinstance(data, dict):<EOL><INDENT>return {k: _extract_and_flatten_nested_structure(v) for k, v in data.items()}<EOL><DEDENT>elif isinstance(data, (mx.sym.Symbol, mx.nd.NDArray)):<EOL><INDENT>flattened.append(data)<EOL>return len(flattened) - <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError<EOL><DEDENT>
Flatten the structure of a nested container to a list.

    Parameters
    ----------
    data : A single NDArray/Symbol or nested container with NDArrays/Symbol.
        The nested container to be flattened.
    flattened : list or None
        The container thats holds flattened result.
    Returns
    -------
    structure : An integer or a nested container with integers.
        The extracted structure of the container of `data`.
    flattened : (optional) list
        The container thats holds flattened result.
        It is returned only when the input argument `flattened` is not given.