def dict_from_prefix(cls, prefix, dictionary):
        """
            >>> from collections import OrderedDict
            >>> od = OrderedDict()
            >>> od["problem[q0][a]"]=1
            >>> od["problem[q0][b][c]"]=2
            >>> od["problem[q1][first]"]=1
            >>> od["problem[q1][second]"]=2
            >>> AdminCourseEditTask.dict_from_prefix("problem",od)
            OrderedDict([('q0', OrderedDict([('a', 1), ('b', OrderedDict([('c', 2)]))])), ('q1', OrderedDict([('first', 1), ('second', 2)]))])
        """
        o_dictionary = OrderedDict()
        for key, val in dictionary.items():
            if key.startswith(prefix):
                o_dictionary[key[len(prefix):].strip()] = val
        dictionary = o_dictionary

        if len(dictionary) == 0:
            return None
        elif len(dictionary) == 1 and "" in dictionary:
            return dictionary[""]
        else:
            return_dict = OrderedDict()
            for key, val in dictionary.items():
                ret = re.search(r"^\[([^\]]+)\](.*)$", key)
                if ret is None:
                    continue
                return_dict[ret.group(1)] = cls.dict_from_prefix("[{}]".format(ret.group(1)), dictionary)
            return return_dict
def dict_from_prefix ( cls , prefix , dictionary ) : o_dictionary = OrderedDict ( ) for key , val in dictionary . items ( ) : if key . startswith ( prefix ) : o_dictionary [ key [ len ( prefix ) : ] . strip ( ) ] = val dictionary = o_dictionary if len ( dictionary ) == 0 : return None elif len ( dictionary ) == 1 and "" in dictionary : return dictionary [ "" ] else : return_dict = OrderedDict ( ) for key , val in dictionary . items ( ) : ret = re . search ( r"^\[([^\]]+)\](.*)$" , key ) if ret is None : continue return_dict [ ret . group ( 1 ) ] = cls . dict_from_prefix ( "[{}]" . format ( ret . group ( 1 ) ) , dictionary ) return return_dict
>>> from collections import OrderedDict
            >>> od = OrderedDict()
            >>> od["problem[q0][a]"]=1
            >>> od["problem[q0][b][c]"]=2
            >>> od["problem[q1][first]"]=1
            >>> od["problem[q1][second]"]=2
            >>> AdminCourseEditTask.dict_from_prefix("problem",od)
            OrderedDict([('q0', OrderedDict([('a', 1), ('b', OrderedDict([('c', 2)]))])), ('q1', OrderedDict([('first', 1), ('second', 2)]))])