def mergedgroupdict(pattern, thestring):
    there = re.compile(pattern)
result = {}
for mo in there.finditer(thestring):
    d = mo.groupdict()
for k in d:
    if k not in result and d[k] is not None:
        result[k] = d[k]
return result
Possible to retrieve an arbitrary unordered set of named groups in one swoop with Python's re module?