Found this strange in python:
class SomeClass():
def __init__(self):
pass
a = [SomeClass()]
b = copy.deepcopy(a)
Output:
>>> a
[<__main__.Some instance at 0x10051b1b8>]
>>> b
[<__main__.Some instance at 0x10051b092>]
This is just as expected- deepcopy created new SomeClass()
object for b.
But if,
f = lambda x:x+1
a = [f]
b = copy.deepcopy(a)
I get:
>>> a
[<function <lambda> at 0x10056e410>]
>>> b
[<function <lambda> at 0x10056e410>]
Why deepcopy doesnt create a new lambda instance in the second case? does that mean lambda functions are atomic?
Technical LimitationsThe maximum time a function can run is 15 minutes, and the default timeout is 3 seconds. Obviously, this makes Lambda unsuitable for long-running workloads. The payload for each invocation of a Lambda function is limited to 6MB, and memory is limited to just under 3GB.
The function allows multiple input arguments. expression : What the function will do in a single expression. Lambda only accepts one expression, but it can generate multiple outputs.
That's not more than one return, it's not even a single return with multiple values. It's one return with one value (which happens to be a tuple).
Lambda functions are a brilliant way to make code more readable and concise.
This applies not just to lambdas, but to functions without state more generally.
>>> def some_function(word): print word
>>> a = [some_function]
>>> a
[<function some_function at 0x1007026e0>]
>>> copy.deepcopy(a)
[<function some_function at 0x1007026e0>]
Because the functions do not store state, deepcopy does not create a new reference for them. An interesting discussion of topics similar to this issue (though not exactly the same issue) is recorded here: http://bugs.python.org/issue1515
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With