from collections import defaultdict
d = defaultdict(str)
d['error2'] = 'success'
s = 'i am an {0[error]} example string {0[error2]}'
print(s.format(d))
python string format suppress/silent keyerror/indexerror