Inspired by a now-deleted question; given a regex with named groups, is there a method like findall which returns a list of dict with the named cap
findall
dict
If you are using match :
r = re.match('(?P[a-z]+)\s+(?P[a-z]+)', text) r.groupdict()
documentation here