def parse_list(string, dtype):
    """
    Parses string of form ``'[as, df]'`` to list of type ``dtype``, e.g. for
    ``dtype=str`` it returns `['as', 'df']``. This works also for a list of lists.

    Parameters
    ----------
    string : string
        Has form ``'[some, entries]``. All entries in the list must have the same type.
    dtype : type converter
        Converter to the type the entries should have, e.g. ``str`` or ``int``

    Returns
    -------
    list of elements of type ``dtype`` or list of lists of elements of type
    ``dtype``. Returns a single value if only a single value is given.
    """
    # l =  string.replace('[', '').replace(']', '').replace(' ', '').split(',')
    s = string.replace(' ', '') # remove all spaces first
    if s[0] == '[': # it's not only a single item
        s = s[1:-1] # remove [ and ] from start and end only
    else: # it's just a single item
        return dtype(s)
    if s[0] == '[': # it's a list of lists
        splitted = s.split('],')
        for i in range(len(splitted)-1):
            splitted[i] += ']' # splitting removed the closing bracket from all but the last item
        l = list(map(lambda x: parse_list(x, dtype), splitted))
    else:
        splitted = s.split(',')
        l = list(map(dtype, splitted))
    return l