Re: Error in lambda function..!

2020-08-29 Thread Rob Cliffe via Python-list
n a+1     add = reduce(myfunc, nums) reduce would call your lambda function succesively with arguments     (1,2)    # which would return 1+1 i.e. 2     (2,3)    # use previous result (2) and next number in the sequence (3); returns 2+1 i.e. 3     (3,4)    # use previous result (3) and next number in

Re: Error in lambda function..!

2020-08-29 Thread Peter Otten
Shivlal Sharma wrote: > from functools import* > nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] > add = reduce(lambda a : a + 1, nums) > print(add) > > error: - > TypeError Traceback (most recent call > last) in () > 1 from functools import* > 2 nums = [1, 2, 3, 4

Error in lambda function..!

2020-08-29 Thread Shivlal Sharma
from functools import* nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] add = reduce(lambda a : a + 1, nums) print(add) error: - TypeError Traceback (most recent call last) in () 1 from functools import* 2 nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] > 3 add = reduce(lambd

Re: Could you explain lambda function to me?

2015-06-02 Thread ast
"fl" a écrit dans le message de news:323866d1-b117-4785-ae24-7d04c49bc...@googlegroups.com... Hi, def make_incrementor(n): ... return lambda x: x + n ... f = make_incrementor(42) f(0) 42 f(1) 43 make_incrementor is a fonction which return a function ! and the returned function jus

Re: Could you explain lambda function to me?

2015-06-02 Thread Chris Kaynor
On Tue, Jun 2, 2015 at 11:14 AM, fl wrote: > Hi, > > I see the description of lambda at the online tutorial, but I cannot > understand it. '42' is transferred to the function. What 'x' value should > be? I do not see it says that it is '0'. And, what is 'x'? > The lambda keyword is merely anothe

Could you explain lambda function to me?

2015-06-02 Thread fl
Hi, I see the description of lambda at the online tutorial, but I cannot understand it. '42' is transferred to the function. What 'x' value should be? I do not see it says that it is '0'. And, what is 'x'? >>> def make_incrementor(n): ... return lambda x: x + n ... >>> f = make_increm

Re: Lambda function Turing completeness

2013-08-24 Thread Piet van Oostrum
This is the second part of my posting on the Turing completeness of Python's lambda expressions. This time I am going to define a recursive function as a lambda expression (I use lambda when I am talking about Python's lambda expressions, and λ for the theory – λ calculus.) Now of course it is eas

Re: Lambda function Turing completeness

2013-08-24 Thread Piet van Oostrum
Musical Notation writes: > Is it possible to write a Turing-complete lambda function (which does > not depend on named functions) in Python? The wording of this question is questionable. Turing completeness is not an attribute of a function, but of a system (for example a programming la

Re: Lambda function Turing completeness

2013-08-01 Thread Ian Kelly
On Wed, Jul 31, 2013 at 11:55 PM, Steven D'Aprano wrote: > On Wed, 31 Jul 2013 13:53:26 +0700, Musical Notation wrote: > >> Is it possible to write a Turing-complete lambda function (which does >> not depend on named functions) in Python? > > > lambda s: e

Re: Lambda function Turing completeness

2013-07-31 Thread Steven D'Aprano
On Wed, 31 Jul 2013 13:53:26 +0700, Musical Notation wrote: > Is it possible to write a Turing-complete lambda function (which does > not depend on named functions) in Python? lambda s: eval(s) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Lambda function Turing completeness

2013-07-31 Thread Ian Kelly
On Wed, Jul 31, 2013 at 12:53 AM, Musical Notation wrote: > Is it possible to write a Turing-complete lambda function (which does not > depend on named functions) in Python? Yes, lambda functions are Turing-complete. You can get anonymous recursion by defining the function to take a rec

Re: Lambda function Turing completeness

2013-07-31 Thread Schneider
On Wed 31 Jul 2013 08:53:26 AM CEST, Musical Notation wrote: Is it possible to write a Turing-complete lambda function (which does not depend on named functions) in Python? what should a sinlge Turing-complete lambda function be? For me, a programming language can be Turing-complete or a

Lambda function Turing completeness

2013-07-31 Thread Musical Notation
Is it possible to write a Turing-complete lambda function (which does not depend on named functions) in Python? -- http://mail.python.org/mailman/listinfo/python-list

Re: How to pickle a lambda function?

2009-08-11 Thread Terry
On Aug 11, 3:42 pm, Duncan Booth wrote: > Terry wrote: > > I'm trying to implement something like: > > > remote_map(fun, list) > > > to execute the function on a remove machine. But the problem is I > > cannot pickle a lambda function and send it to

Re: How to pickle a lambda function?

2009-08-11 Thread Duncan Booth
Terry wrote: > I'm trying to implement something like: > > remote_map(fun, list) > > to execute the function on a remove machine. But the problem is I > cannot pickle a lambda function and send it to the remote machine. > > Is there any possible way to pickle (o

How to pickle a lambda function?

2009-08-10 Thread Terry
Hi, I'm trying to implement something like: remote_map(fun, list) to execute the function on a remove machine. But the problem is I cannot pickle a lambda function and send it to the remote machine. Is there any possible way to pickle (or other method) any functions including lambda

Re: Lambda function

2009-02-25 Thread Gabriel Genellina
En Wed, 25 Feb 2009 12:42:32 -0200, Albert Hopkins escribió: On Wed, 2009-02-25 at 17:56 +0530, aditya saurabh wrote: I defined two functions - lets say fa = lambda x: 2*x fb = lambda x: 3*x Now I would like to use fa*fb in terms of x is there a way? Thanks in advance I'm not sure what "us

Re: Lambda function

2009-02-25 Thread Albert Hopkins
On Wed, 2009-02-25 at 17:56 +0530, aditya saurabh wrote: > I defined two functions - lets say > fa = lambda x: 2*x > fb = lambda x: 3*x > Now I would like to use fa*fb in terms of x > is there a way? > Thanks in advance I'm not sure what "use fa*fb in terms of x" means. But if you mean fa(x) * fb

Lambda function

2009-02-25 Thread aditya saurabh
I defined two functions - lets say fa = lambda x: 2*x fb = lambda x: 3*x Now I would like to use fa*fb in terms of x is there a way? Thanks in advance -- http://mail.python.org/mailman/listinfo/python-list

Re: dynimac code with lambda function creation

2008-03-27 Thread Justin Delegard
unction'). FWIW and WWAI, Python's methods are thin callable wrappers around the function, the class and (for bound methods) the instance. I figured an easy way to do it would be to create a lambda function that calls the correct method, but this is proving more difficult tha

Re: dynimac code with lambda function creation

2008-03-27 Thread Bruno Desthuilliers
nter. s/pointer/object/ There's nothing like a pointer in Python, and Python's functions are plain objects (instances of class 'function'). FWIW and WWAI, Python's methods are thin callable wrappers around the function, the class and (for bound methods) the instance. >

Re: dynimac code with lambda function creation

2008-03-27 Thread Laszlo Nagy
Justin Delegard wrote: > So I am trying to pass an object's method call to a function that > requires a function pointer. I figured an easy way to do it would be to > create a lambda function that calls the correct method, but this is > proving more difficult than I imagined

dynimac code with lambda function creation

2008-03-27 Thread Justin Delegard
So I am trying to pass an object's method call to a function that requires a function pointer. I figured an easy way to do it would be to create a lambda function that calls the correct method, but this is proving more difficult than I imagined. Here is the function I'm u

Re: Is this a bug of the lambda function

2007-10-12 Thread Carsten Haese
j (which is declear with the lambda > function), I can get expected answer [...] 'j' is not declared with the lambda function. Inside the lambda, 'j' is a global name. Global names inside a function body are looked up when the function is called, not when the function is def

Is this a bug of the lambda function

2007-10-11 Thread Zhu Wayne
result is very strange: print f[k](1.), 4.0 4.0 4.0 4.0 4.0 expect 0. 1. 2. 3. 4. print f[j](1.), 0.0 1.0 2.0 3.0 4.0 expect 0. 1. 2. 3. 4. print f[0](1.), f[1](1.), ... 4.0 4.0 4.0 4.0 4.0 expect 0. 1. 2. 3. 4. It seems only when I use the index j (which is declear with the lambda funct