Re: initialized list: strange behavior

2008-11-25 Thread Arnaud Delobelle
Jason Scheirer [EMAIL PROTECTED] writes: On Nov 24, 10:34 pm, [EMAIL PROTECTED] wrote: Hi Python experts! Please explain this behavior: nn=3*[[]] nn [[], [], []] mm=[[],[],[]] mm [[], [], []] Up till now, 'mm' and 'nn' look the same, right? Nope! mm[1].append(17) mm [[],

Re: initialized list: strange behavior

2008-11-25 Thread Benjamin Kaplan
On Tue, Nov 25, 2008 at 9:23 AM, Arnaud Delobelle [EMAIL PROTECTED]wrote: Jason Scheirer [EMAIL PROTECTED] writes: On Nov 24, 10:34 pm, [EMAIL PROTECTED] wrote: Hi Python experts! Please explain this behavior: nn=3*[[]] nn [[], [], []] mm=[[],[],[]] mm [[], [], []]

Re: initialized list: strange behavior

2008-11-25 Thread Steve Holden
Arnaud Delobelle wrote: Jason Scheirer [EMAIL PROTECTED] writes: On Nov 24, 10:34 pm, [EMAIL PROTECTED] wrote: Hi Python experts! Please explain this behavior: nn=3*[[]] nn [[], [], []] mm=[[],[],[]] mm [[], [], []] Up till now, 'mm' and 'nn' look the same, right? Nope!

Re: initialized list: strange behavior

2008-11-25 Thread alexander . genkin
The issue is exhausted in Python Library Reference, Chapter 3.6, so I should apologize for initial posting. All comments were helpful, though Arnaud and Steve are right that pass-by-anything is off the point. Thanks All! -- http://mail.python.org/mailman/listinfo/python-list

Re: initialized list: strange behavior

2008-11-25 Thread Arnaud Delobelle
Steve Holden [EMAIL PROTECTED] writes: Arnaud Delobelle wrote: Jason Scheirer [EMAIL PROTECTED] writes: Python is pass-by-reference, not pass-by-value. It's certainly not pass-by-reference, nor is it pass-by-value IMHO. Since no lists are being passed as arguments in these examples it's

initialized list: strange behavior

2008-11-24 Thread alexander . genkin
Hi Python experts! Please explain this behavior: nn=3*[[]] nn [[], [], []] mm=[[],[],[]] mm [[], [], []] Up till now, 'mm' and 'nn' look the same, right? Nope! mm[1].append(17) mm [[], [17], []] nn[1].append(17) nn [[17], [17], [17]] ??? Python 2.5 Win XP Thanks! --

Re: initialized list: strange behavior

2008-11-24 Thread Gary Herron
[EMAIL PROTECTED] wrote: Hi Python experts! Please explain this behavior: [] make an empty list. [ [],[],[] ] makes a list of three different empty lists. 3*[[]] makes a list of three references to the same list. Realy, that should explain it all, but perhaps there are enough empty lists

Re: initialized list: strange behavior

2008-11-24 Thread Jason Scheirer
On Nov 24, 10:34 pm, [EMAIL PROTECTED] wrote: Hi Python experts! Please explain this behavior: nn=3*[[]] nn [[], [], []] mm=[[],[],[]] mm [[], [], []] Up till now, 'mm' and 'nn' look the same, right? Nope! mm[1].append(17) mm [[], [17], []] nn[1].append(17) nn [[17],