how to change parent function's arguments in high order function in python
up vote
0
down vote
favorite
def make_repeater(f, n):
def a(x):
total = x
while n > 0:
total = f(total)
n -= 1
return total
return a
make_repeater(lambda x: x + 1, 3)(5)
get error: UnboundLocalError: local variable 'n' referenced before assignment
how to solve this problem?
python-3.x
add a comment |
up vote
0
down vote
favorite
def make_repeater(f, n):
def a(x):
total = x
while n > 0:
total = f(total)
n -= 1
return total
return a
make_repeater(lambda x: x + 1, 3)(5)
get error: UnboundLocalError: local variable 'n' referenced before assignment
how to solve this problem?
python-3.x
docs.python.org/3/reference/…
– bruno desthuilliers
Nov 8 at 8:46
it works, think you very much
– Joey Wei
Nov 8 at 8:56
you're welcome ;-)
– bruno desthuilliers
Nov 8 at 8:58
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
def make_repeater(f, n):
def a(x):
total = x
while n > 0:
total = f(total)
n -= 1
return total
return a
make_repeater(lambda x: x + 1, 3)(5)
get error: UnboundLocalError: local variable 'n' referenced before assignment
how to solve this problem?
python-3.x
def make_repeater(f, n):
def a(x):
total = x
while n > 0:
total = f(total)
n -= 1
return total
return a
make_repeater(lambda x: x + 1, 3)(5)
get error: UnboundLocalError: local variable 'n' referenced before assignment
how to solve this problem?
python-3.x
python-3.x
asked Nov 8 at 8:28
Joey Wei
31
31
docs.python.org/3/reference/…
– bruno desthuilliers
Nov 8 at 8:46
it works, think you very much
– Joey Wei
Nov 8 at 8:56
you're welcome ;-)
– bruno desthuilliers
Nov 8 at 8:58
add a comment |
docs.python.org/3/reference/…
– bruno desthuilliers
Nov 8 at 8:46
it works, think you very much
– Joey Wei
Nov 8 at 8:56
you're welcome ;-)
– bruno desthuilliers
Nov 8 at 8:58
docs.python.org/3/reference/…
– bruno desthuilliers
Nov 8 at 8:46
docs.python.org/3/reference/…
– bruno desthuilliers
Nov 8 at 8:46
it works, think you very much
– Joey Wei
Nov 8 at 8:56
it works, think you very much
– Joey Wei
Nov 8 at 8:56
you're welcome ;-)
– bruno desthuilliers
Nov 8 at 8:58
you're welcome ;-)
– bruno desthuilliers
Nov 8 at 8:58
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
draft saved
draft discarded
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203906%2fhow-to-change-parent-functions-arguments-in-high-order-function-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
docs.python.org/3/reference/…
– bruno desthuilliers
Nov 8 at 8:46
it works, think you very much
– Joey Wei
Nov 8 at 8:56
you're welcome ;-)
– bruno desthuilliers
Nov 8 at 8:58