Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: changing parts of a list of lists

  • To: mathgroup at
  • Subject: [mg52606] Re: changing parts of a list of lists
  • From: astanoff_otez_ceci at (astanoff)
  • Date: Sat, 4 Dec 2004 04:07:46 -0500 (EST)
  • References: <comgeg$62q$>
  • Sender: owner-wri-mathgroup at

Dan Drake wrote:

> I'm working with a list of lists, such as {{1,2}, {3}, {4,5,6}}, and I
> want to go through and make changes to each sublist, but I get the error
> message "Set::setps: {{0,0,0},{0},{0}} in assignment of part is not a
> symbol."
> I don't quite understand what's going on. Here's a toy example that
> shows the error:
> f[x:{__List}] := For[i=1, i <= Length[x], i++, x[[i]] = {1, 2, 3}]


Let me quote David B. Wagner : "the best of doing something [with 
is almost never the procedural way".

So you better not use For, Do or While to do what you want to do.

Why not simply use Map or MapAt?

In addition it's often better performance not to modify a large list in 

For example if you want to prepend a zero to each of your sublists
you could do it this way :

In[1]:=myList = {{1,2},{3},{4,5,6}};

In[2]:=newList = Map[Prepend[#,0]&,myList]




0% de pub! Que du bonheur et des vrais adhérents !
Vous aussi inscrivez-vous sans plus tarder!!
Message posté à partir de, BBS actif depuis 1995.

  • Prev by Date: Re: Finding the Fourier transform of discrete functions
  • Next by Date: A problem of numerical precision
  • Previous by thread: Re: changing parts of a list of lists
  • Next by thread: Invoking a function using full package name fail, but works without full package name