Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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: extracting a list to a list, help please

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46174] RE: [mg46155] extracting a list to a list, help please
  • From: "David Park" <djmp at earthlink.net>
  • Date: Tue, 10 Feb 2004 00:05:41 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Serge,

This is where pure functions and functional programming come in handy. We
want to Take the first two items of each sublist, and we would like to Map
that action onto all the sublists in mylist1.

mylist1 = {{a1, b1, c1, d1}, {a2, b2, c2, d2}, {a3, b3, c3, d3}};

Take[#, 2] & /@ mylist1
{{a1, b1}, {a2, b2}, {a3, b3}}

Take[#, 2]& is a pure function. It will take the first two items of any
object it operates on. /@ is the Mathematica shorthand for Map. It causes
the Take function to operate on all the first level items in mylist1. You
might want to look up Take, Map and pure functions in Help.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/


From: Serge [mailto:nospam at nospam.com]
To: mathgroup at smc.vnet.net


Hello,

I am a beginner in Mathematica and I have a rather simple question. I
made some calculations that I need for an orbit and I have a list that
look like this:

mylist1 = {{a1,b1,c1,d1},{a2,b2,c2,d2},{a3,b3,c3,d3},etc}

All I want to do is to make a list of the form

mylist2 = {{a1,b1},{a2,b2},{a3,b3},etc}

from the original list (mylist1),

so that I can ListPlot those pairs of points (they represent x and y
coordinates for some orbit). I am having trouble figuring out how to do
this. I tried using the Table command but I couldn't get it into the
above form. I would greatly appreciate if someone can help me out.
Thanks so much.

Best,
Serge



  • Prev by Date: Re: extracting a list to a list, help please
  • Next by Date: Re: Mathematical Statistics
  • Previous by thread: Re: extracting a list to a list, help please
  • Next by thread: Re: extracting a list to a list, help please