MathGroup Archive 2008

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

Search the Archive

Re: more looping trouble

  • To: mathgroup at
  • Subject: [mg85451] Re: more looping trouble
  • From: "Steve Luttrell" <steve at>
  • Date: Mon, 11 Feb 2008 06:06:27 -0500 (EST)
  • References: <fomjsd$hsj$>

Stop trying to use loops! Read up about the use of patterns and replacement 
rules in Mathematica.

You need to define a replacement rule that matches each entry in your list, 
and then replaces it by the corresponding entry with the last element 
removed. There are lots of patterns you could use to achieve this effect, 
and here is one that I have written (rather verbosely to illustrate some of 
the things can be done - look them up in the documentation) to achieve the 
effect that you want:

{{1,2,3}, {2,3,4}}/.{x_?NumberQ, y_?NumberQ, _?NumberQ}->{x, y}

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

There are other ways of obtaining the result you seek, all of which involve 
Mathematica operations applied to whole lists rather than using loops to 
address individual list elements.

Stephen Luttrell
West Malvern, UK

"Francis Bitonti" <frankb.mail at> wrote in message 
news:fomjsd$hsj$1 at
> Sorry for these lame questions but I'm still trying to get my head around
> loops. I though I had it but I hit a snag today.
> I have a table of numbers {{1,2,3},{2,3,4}} I want to use a loop to remove
> the third integer in each set and reassemble them as a new table.
> However, something is going wrong I think it's because i'm not grasping 
> some
> fundamental idea about how to perform these type of operations on tables.
> -- 
> _Francis Bitonti
> web:

  • Prev by Date: Re: more looping trouble
  • Next by Date: Re: Import syntax question
  • Previous by thread: Re: more looping trouble
  • Next by thread: Re: more looping trouble