On Sat, 12 Jul 2008 16:32:25 -0400, Terry Reedy wrote:
Steven D'Aprano wrote:
On Thu, 10 Jul 2008 14:09:16 -0400, Terry Reedy wrote:
g = lambda x:validate(x)
This is doubly diseased.
First, never write a 'name = lambda...' statement since it is
equivalent to a def statement except that
On Thu, 10 Jul 2008 14:09:16 -0400, Terry Reedy wrote:
g = lambda x:validate(x)
This is doubly diseased.
First, never write a 'name = lambda...' statement since it is equivalent
to a def statement except that the resulting function object lacks a
proper .funcname attribute.
Using lambda
Steven D'Aprano wrote:
On Thu, 10 Jul 2008 14:09:16 -0400, Terry Reedy wrote:
g = lambda x:validate(x)
This is doubly diseased.
First, never write a 'name = lambda...' statement since it is equivalent
to a def statement except that the resulting function object lacks a
proper .funcname
In article [EMAIL PROTECTED],
Terry Reedy [EMAIL PROTECTED] wrote:
David C. Ullrich wrote:
In article
[EMAIL PROTECTED],
ssecorp [EMAIL PROTECTED] wrote:
I am never redefining the or reassigning the list when using validate
but since it spits the modified list back out that
In article
[EMAIL PROTECTED],
ssecorp [EMAIL PROTECTED] wrote:
def mod(x,y):
return x.append(y)
mod([1,2],3)
k=[1,2,3]
k
[1, 2, 3]
l = mod(k,4)
l
k
[1, 2, 3, 4]
l
k==l
False
mod(k,5)
k
[1, 2, 3, 4, 5]
mod(l,4)
Traceback (most recent call last):
File
I am never redefining the or reassigning the list when using validate
but since it spits the modified list back out that somehow means that
the modified list is part of the environment and not the old one.
i thought what happend inside a function stays inside a function
meaning what comes out is
Python doesn't use value semantics for variables but reference semantics:
a = [1]
b = a
In many languages, you'd now have 2 lists. In Python you still have one list,
and both a and b refer to it.
Now if you modify the data (the list), both variables will change
a.append(2) # in-place
In article
[EMAIL PROTECTED],
ssecorp [EMAIL PROTECTED] wrote:
I am never redefining the or reassigning the list when using validate
but since it spits the modified list back out that somehow means that
the modified list is part of the environment and not the old one.
i thought what happend
David C. Ullrich wrote:
In article
[EMAIL PROTECTED],
ssecorp [EMAIL PROTECTED] wrote:
I am never redefining the or reassigning the list when using validate
but since it spits the modified list back out that somehow means that
the modified list is part of the environment and not the old
ty very good answer. i know i shouldn't use lambda like that, i never
do i was just playing around there and then this happened which i
thought was weird.
On Jul 10, 8:09 pm, Terry Reedy [EMAIL PROTECTED] wrote:
David C. Ullrich wrote:
In article
[EMAIL PROTECTED],
ssecorp [EMAIL
def mod(x,y):
return x.append(y)
mod([1,2],3)
k=[1,2,3]
k
[1, 2, 3]
l = mod(k,4)
l
k
[1, 2, 3, 4]
l
k==l
False
mod(k,5)
k
[1, 2, 3, 4, 5]
mod(l,4)
Traceback (most recent call last):
File pyshell#29, line 1, in module
mod(l,4)
File pyshell#18, line 2, in mod
return
On Jul 10, 9:46 pm, ssecorp [EMAIL PROTECTED] wrote:
def mod(x,y):
return x.append(y)
append adds y to list x and returns None, which is then returned by
mod.
mod([1,2],3)
k=[1,2,3]
k
[1, 2, 3]
l = mod(k,4)
4 has been appended to list k and mod has returned None, so l is
12 matches
Mail list logo