The following snippet-code complains error saying that "unresolved reference maxFreq":
def returnItemsWithMinSupport():
maxFreq = -1
def recInFreqSet():
if 2 > maxFreq:
maxFreq = 1
return 3
But if I change it to the following, it complains nothing:
def returnItemsWithMinSupport():
maxFreq = -1
def recInFreqSet():
if 2 > maxFreq:
x = 1
return 3
Why is that? Great thanks.
nonlocal maxFreqallowing outer variable set. Seenonlocalstatemetn.returnItemsWithMinSupport(), you will see exception. (you need to modify thereturnItemsWithMinSupportalso to callrecInFreqSet)