import re def get_dict_from_query(query, name): d = {} matcher = re.compile("^%s\[(.+)\]$" % name) for key, value in query.items(): match = matcher.match(key) if match is not None: d[match.group(1)] = value return d