Re: Assigning to a sublist

• To: mathgroup at smc.vnet.net
• Subject: [mg35182] Re: Assigning to a sublist
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Fri, 28 Jun 2002 02:31:49 -0400 (EDT)
• References: <afe4lv\$h2h\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Bob,

zz={{2,{{1,1}}},{10,{{3,1}}},{5,{{2,1}}}};

zz[[3,2]] (*not  zz[[3]][[2]]*)  = Append[zz[[3]][[2]],{1,1,1,1,1}];

zz[[3,2]]

{{2,1},{1,1,1,1,1}}

--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Bob Harris" <nitlion at mindspring.com> wrote in message
news:afe4lv\$h2h\$1 at smc.vnet.net...
> Howdy,
>
> I'm trying to assign a new value to an entry in a sublist (of another
list),
> and I can't understand why it won't work.
>
> For example, I do the following:
>
>   In[1]:= zz = {{2, {{1, 1}}}, {10, {{3, 1}}}, {5, {{2, 1}}}}
>   Out[1]= {{2, {{1, 1}}}, {10, {{3, 1}}}, {5, {{2, 1}}}}
>
>   In[2]:= zz[[3]][[2]]
>   Out[2]= {{2, 1}}
>
>   In[3]:= Append[zz[[3]][[2]], {1, 1, 1, 1, 1}]
>   Out[3]= {{2, 1}, {1, 1, 1, 1, 1}}
>
>   In[4]:= zz[[3]][[2]] = Append[zz[[3]][[2]], {1, 1, 1, 1, 1}]
>   Set::"setps : zz[[3]] in assignment of part is not a symbol."
>   Out[4]= {{2, 1}, {1, 1, 1, 1, 1}}
>
> For some reason it doesn't like the assignment.  What confuses me is that
is
> zz[[3]][[2]] were just a variable, it would work.  Further, if it were
just
> an entry at the *top* level of a list, it would work, as this example
shows:
>
>   In[5]:= yy = zz[[3]]
>   Out[5]= {5, {{2, 1}}}
>
>   In[6]:= yy[[2]]
>   Out[6]= {{2, 1}}
>
>   In[7]:= yy[[2]] = Append[yy[[2]], {1, 1, 1, 1, 1}]
>   Out[7]= {{2, 1}, {1, 1, 1, 1, 1}}
>
> So it seems like the issue is just that deeply nested things don't behave
> like things that are not as deeply nested.  Am I right about that?  How
can
> I modify an entry in a sublist?
>
> Thanks,
> Bob H
>
>

```

• Prev by Date: Re: help on backtesting
• Next by Date: Re: Assigning to a sublist
• Previous by thread: Re: Assigning to a sublist
• Next by thread: Re: Assigning to a sublist