s = '<sometag>this is stuff<othertag>this is other stuff<closetag>'
d = {'othertag': 'blah'}
re.sub('<(\\w+)>', lambda m: d.get(m.group(), m.group()), s)
Python Regex Sub - Use Match as Dict Key in Substitution