Hello, I request help in understanding why I'm getting NameError here in the code below: import re def t(s): k = [] def g(j): global k k.append(j.group(0)) return 'p' re.sub('f',g,s) print k if __name__ == "__main__": t('abc f xyz f') Thanks in advance, Shadri