MathGroup Archive 1996

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3970] Re: list
  • From: ianc (Ian Collier)
  • Date: Mon, 13 May 1996 01:47:37 -0400
  • Organization: Wolfram Research, Inc.
  • Sender: owner-wri-mathgroup at wolfram.com

In article <4lse5f$hjq at dragonfly.wolfram.com>, Ahmad Khalid
<khalid at ciril.fr> wrote:

> i just start with mathematica.. i just want to know how can we modifie a list
> of list in mathematica. (ex { {1,2,3},{3,4,5},{5,6,7}})
> thank you

If you simply want to replace elements in your list here 
are two ways:

In[7]:=
    mylist = { {1,2,3},{3,4,5},{5,6,7}}
Out[7]=
    {{1, 2, 3}, {3, 4, 5}, {5, 6, 7}}

In[8]:=
    ?ReplacePart

    ReplacePart[expr, new, n] yields an expression in which the
       nth part of expr is replaced by new. ReplacePart[expr,
       new, {i, j, ...}] replaces the part at position {i, j,
       ...}. ReplacePart[expr, new, {{i1, j1, ...}, {i2, j2,
       ...}, ...}] replaces parts at several positions by new.

In[9]:=
    mylist = ReplacePart[ mylist, a^2, {1,2}]
Out[9]=
          2
    {{1, a , 3}, {3, 4, 5}, {5, 6, 7}}

In[10]:=
    mylist
Out[10]=
          2
    {{1, a , 3}, {3, 4, 5}, {5, 6, 7}}

In[11]:=
    mylist[[2,2]] = c
Out[11]=
    c

In[12]:=
    mylist
Out[12]=
          2
    {{1, a , 3}, {3, c, 5}, {5, 6, 7}}

You can also add and remove elements. For further details see
section 1.8.6 of the Mathematica book, "Adding, Removing and 
Modifying List Elements.

If you require further help with this I would suggest that you 
contact Wolfram Research Technical Support (support at wolfram.com) 
directly including specific details of what you are trying to do.

I hope this helps.

--Ian

-----------------------------------------------------------
Ian Collier
Wolfram Research, Inc.
-----------------------------------------------------------
tel:(217) 398-0700   fax:(217) 398-0747    ianc at wolfram.com
Wolfram Research Home Page:         http://www.wolfram.com/
-----------------------------------------------------------


==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Re: Context Names Question
  • Next by Date: Re: how to draw the contour lines on a surface
  • Previous by thread: Re: list
  • Next by thread: Re: Bottom line on remote kernel