I have a function that uses functools LRU cache, but I want to pass in some non-input parameters e.g. "a"
import functools
import random
def foo(d, a):
@functools.lru_cache()
def bar(d):
random.seed(d)
nonlocal a
a = []
s = 0
for i in range(100):
r = random.random()
a.append(r)
s += r
if s < 50:
return True
else:
return False
return bar(d)
But when I use these functions, "a" is not changed:
a = []
print(foo(random.randint(0, 100), a))
print(a)
What's going on? Also is this the right way to use functools, nested?
Update
I used this in the end i.e. with global and without foo:
@functools.lru_cache()
def bar(d):
global a
random.seed(d)
...