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
you could switch to finditer
>>> import re >>> text = "bob sue jon richard harry" >>> pat = re.compile('(?P[a-z]+)\s+(?P[a-z]+)') >>> for m in pat.finditer(text): ... print m.groupdict() ... {'name2': 'sue', 'name': 'bob'} {'name2': 'richard', 'name': 'jon'}