Pierre wrote:
> I would like to know if it is possible to define a loop in a lambda
> function
It is if you can easily replace the for loop with a call to map():
>>> s_minus_1 = lambda s: map(lambda x: x-1, s)
>>> test = range(1, 100, 10)
>>> test
[1, 11, 21, 31, 41, 51, 61, 71, 81, 91]
>>>
On Mon, 31 Aug 2009 08:41:57 +0100, Pierre
wrote:
Hello,
I would like to know if it is possible to define a loop in a lambda
function
How to manage the indents ? Example :
s_minus_1 = lambda s : for index in range(0, len(s)) : s[index] = s
[index]-1
You can't use commands in a lambda
Pierre writes:
> s_minus_1 = lambda s : for index in range(0, len(s)) : s[index] = s
> [index]-1
What are you trying to do here anyway? That looks broken.
Maybe you want the list.insert method.
--
http://mail.python.org/mailman/listinfo/python-list
En Mon, 31 Aug 2009 04:41:57 -0300, Pierre
escribió:
I would like to know if it is possible to define a loop in a lambda
function
How to manage the indents ? Example :
s_minus_1 = lambda s : for index in range(0, len(s)) : s[index] = s
[index]-1
You can't. lambda is just a way to defin
On Mon, Aug 31, 2009 at 12:41 AM, Pierre wrote:
> Hello,
>
> I would like to know if it is possible to define a loop in a lambda
> function
Not possible. Lambdas can only contain a single expression. A loop is
a block statement.
Just use a named function instead. There's nothing that can be do
Hello,
This page has some advice about how to avoid some of the lambda
functions limitations:
http://p-nand-q.com/python/stupid_lambda_tricks.html
In particular, it suggests to use map function instead of for loops.
Best regards,
Javier
2009/8/31 Pierre :
> Hello,
>
> I would like to know i
> This means that "f" is not a pointer to make_incrementor but rather to
> the internal (copied?) function.
"returned" function isthe right here. As any returned object from a function.
>
> > This style is very common in Scheme programming so you might read a
> > Scheme book if you want to underst
Wow,
Thank you everyone for the help. I am amazed by the motivation people
have on this list to help new comers. I hope that I will be able to
contribute equally some day.
On 05 Feb 2007 14:22:05 -0800, Paul Rubin
<"http://phr.cx"@nospam.invalid> wrote:
> "Maxim Veksler" <[EMAIL PROTECTED]> write
Maxim Veksler wrote:
> And what is the "f" object? An integer? a pointer? an Object?
A function.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/CSS/Javascript/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
--
http://mail.python.org/mai
Maxim Veksler a écrit :
> Hello,
> I'm new on this list and in python.
Welcome on board...
> It seems python has some interesting concept of "ad hoc" function
> which I'm trying to understand without much success.
>
> Take the following code for example:
>
> """
>
def make_incrementor(n):
"Maxim Veksler" <[EMAIL PROTECTED]> writes:
> >>> def make_incrementor(n):
> ... return lambda x: x + n
Is the same as:
def make_incrementor(n):
def inner(x):
return x + n
return inner
When you enter make_incrementor, it allocates a memory slot (normally
we'd think of this as
Maybe you would like a generator:
>>> def f(n):
... while True:
... n += 1
... yield n
...
>>> a = f(5)
>>>
>>> a.next()
6
>>> a.next()
7
>>> a.next()
8
>>> a.next()
9
>>>
On 2/5/07, Maxim Veksler <[EMAIL PROTECTED]> wrote:
> Hello,
> I'm new on this list and in pytho
Valid link in my previews message is
http://mail.python.org/pipermail/python-dev/2005-September/056669.html
Sorry.
--
http://mail.python.org/mailman/listinfo/python-list
OK.
The thing i've got is an obscure semantic bug, occured because of my
unawareness of the following Python "features":
1. (In major)
http://mail.python.org/pipermail/python-dev/2005-September/056508.html
2. "late" bindings of the function's body
Got to know! :)
Thanks for your attention.
--
h
Max Rybinsky <[EMAIL PROTECTED]> wrote:
> Thank you for explanation, Alex.
> It appears that almost every beginner to Python gets in trouble with
> this ...feature. :)
Almost every beginner to Python gets in trouble by expecting "do what
I'm thinking of RIGHT NOW"-binding, which no language offer
Thank you for explanation, Alex.
It appears that almost every beginner to Python gets in trouble with
this ...feature. :)
--
http://mail.python.org/mailman/listinfo/python-list
On 29 Oct 2005 14:25:24 -0700, Max Rybinsky <[EMAIL PROTECTED]> wrote:
>Hello!
>
>Please take a look at the example.
>
a = [(x, y) for x, y in map(None, range(10), range(10))] # Just a list of
tuples
a
>[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8,
>8), (9, 9)
Max Rybinsky <[EMAIL PROTECTED]> wrote:
...
> >>> funcs = [lambda n: x * y / n for x, y in a]
...
> It seems, all functions have x and y set to 9.
> What's wrong with it? Is it a bug?
It's known as *late binding*: names x and y are looked up when the
lambda's body is executing, and at that t
18 matches
Mail list logo