I was given this task:
Write a one-line expression that converts the function f (x) to f (x) +1. Hint: Consider how a local frame binding for a stored value of f can be created without assignment .Example:>>> f = lambda x: x*x >>> f(5) 25 >>> ---your one line expression--- >>> f(5) 26 >>> f, g = None, f >>> g(5) 26
Write a one-line expression that converts the function f (x) to f (x) +1. Hint: Consider how a local frame binding for a stored value of f can be created without assignment .
Example:
>>> f = lambda x: x*x >>> f(5) 25 >>> ---your one line expression--- >>> f(5) 26 >>> f, g = None, f >>> g(5) 26
I tried to do this:
k,f=f, lambda x: k(x)+1
And it works, but uses the assignment f=f. How could I do this without an appointment?
f=f
My teacher told me that Python has a function similar to a function letin Scheme, but I'm not sure that this function wants us to use it because it did not specify the name of the function.
let
This will work, but it could be a hoax:
>>> f = lambda x: x*x >>> f(5) 25 >>> globals().update({'f': (lambda g: lambda x: g(x)+1)(f)}) >>> f(5) 26 >>> f, g = None, f >>> g(5) 26
, , , :
def f(x, f=f): return f(x) + 1
" () ", , , .
Source: https://habr.com/ru/post/1568034/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1568029/spring-data-repository-detached-entity-passed-to-persist&usg=ALkJrhg6F-80io3JHH3lswc5ViutAVn39gHow to highlight a specific line in the ACE editor? - javascriptКак присоединиться к модели в solr с рельсами sunspot - ruby-on-railsHow to create a typically limited property on an interface? - genericsRequest repo using string - elixirlast part of resource identifier in var - javascriptCombining two IEnumerable queries into one - c #Open safari developer tools for quick file access - safariAdd X-Auth-Token - C # HttpClient - c #Assigning a query result to a variable - pythonAll Articles