Is there a way to access the local variable of a function from a function that is defined within said function?
Y is a tuple with strings, and I want whatever caps becomes when a condition is met to stay the same for the next call with the next item in y. I tried to use the built-in function global, but I guess that only works for globals.
def cap_sentence(y):
caps = "on"
def func(x):
if caps == "on"
caps = "off"
return x.capitalize()
elif "." in x:
caps = "on"
return tuple(map(func, y))
Use
nonlocalin Python 3.x:In python 2.7: