<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def list_to_dict(lst, key=None, remove_key=True):
 """ convert a list of dicts to a dict with root keys Parameters lst : list[dict] key : str or None a key contained by all of the dicts if None use index number string remove_key : bool remove key from dicts in list Examples -------- {'0': {'b': 1, 'name': 'f'}, '1': {'c': 2, 'name': 'g'}} {'f': {'b': 1}, 'g': {'c': 2}} """


    assert all([is_dict_like(d) for d in lst])
    if key is not None:
        assert all([key in d for d in lst])
    new_dict = {}
    for i, d in enumerate(lst):
        d = unflatten(flatten(d))
        if key is None:
            new_dict[str(i)] = d
        else:
            if remove_key:
                k = d.pop(key)
            else:
                k = d[key]
            new_dict[k] = d

    return new_dict