Hi,
Alex wrote:
Hi all!
I have a problem understanding the behaviour of this snippet:
data_set = ({"param":"a"},{"param":"b"},{"param":"c"})
for i in range(len(data_set)):
ds = data_set[:]
data = ds[i]
if i == 1: data['param'] = "y"
if i == 2: data['param'] = "x"
print da
On Sep 21, 7:48 pm, Peter Pearson <[EMAIL PROTECTED]> wrote:
> FWIW, since I started following this newsgroup, I've noticed
> that I no longer have those crises that revolve around the depth
> of a copy. I conjecture that they resulted from non-pythonic
> style. Try following this newsgroup for
On Sun, 21 Sep 2008 06:17:36 -0700 (PDT), Alex wrote:
> On 21 Set, 15:07, George Sakkis <[EMAIL PROTECTED]> wrote:
>> On Sep 21, 8:51 am, Alex <[EMAIL PROTECTED]> wrote:
[snip]
>> > I have a problem understanding the behaviour of this snippet:
[snip]
>> Because you're doing a shallow copy:
>> http:
On 21 Set, 15:07, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Sep 21, 8:51 am, Alex <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi all!
>
> > I have a problem understanding the behaviour of this snippet:
>
> > data_set = ({"param":"a"},{"param":"b"},{"param":"c"})
>
> > for i in range(len(data_set)):
>
On Sep 21, 10:51 pm, Alex <[EMAIL PROTECTED]> wrote:
> Why? I'm coping data_set in ds so why data_set is changed?
You're making a copy of the ds tuple, which has the -same- contents as
the original. To create copies of the contents as well, try the
deepcopy function from the copy module.
As an as
On Sep 21, 8:51 am, Alex <[EMAIL PROTECTED]> wrote:
> Hi all!
>
> I have a problem understanding the behaviour of this snippet:
>
> data_set = ({"param":"a"},{"param":"b"},{"param":"c"})
>
> for i in range(len(data_set)):
> ds = data_set[:]
> data = ds[i]
> if i == 1: data['param'] = "y