RE: Extracting elements of lists

• To: mathgroup at smc.vnet.net
• Subject: [mg45491] RE: [mg45458] Extracting elements of lists
• From: "David Park" <djmp at earthlink.net>
• Date: Sat, 10 Jan 2004 00:00:38 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```The best chances of obtaining a good answer to a question like this is to
supply a COMPLETE set of data that the responder can use to test your

The responder can try to make up a set of test data, but this is often a lot
of work and may depart from the actual characteristics of your data.

Secondly, you haven't clearly stated what the rule is for extraction. Is the
responder supposed to surmise it from a routine you have written that you
say doesn't work?

Nevertheless, some of the people on MathGroup are so good that they may
still be able to make the right assumptions and give you a good answer. It
is just that your chances go up with a clearly defined and stated question.

David Park

From: sashan [mailto:nothing at important.com]
To: mathgroup at smc.vnet.net

Hi

I'm trying to extract a elements from a list and return another list
with those elements. I've tried doing it using a while loop and
recursion and haven't been able to do it.

The list I'm working with is a list of lists where each inner list
contains 4 elements. Example:
{{0, 1, 0, 0}, {0.04, 1, -0.0008, 0}, {0.1, 0.999987, -0.00499995,
0}, {0.15, 0.999937, -0.0112494, 0}, {0.18, 0.999869, -0.0161983,
0},....

This is my recursive attempt:

listoftimex[l_] := {{First[l][[1]], First[l][[2]]}, listoftimex[Rest[l]]}

{{0, 1}, {{0.04,
1}, {{0.1, 0.999987}, {{
0.15, 0.999937}, {{0.18, 0.999869}, {{0.23, 0.99965}, {{0.26,
0.999429}, \
{{0.31, 0.998847}, {{0.35, 0.998128}, {{0.39,

It extracts the 1st 2 elements of the list and puts them in a list but
it nests lists too deep (too many { ) and it errors with 'Recursion
depth of 256 exceeded'.

This is my attempt using a while loop:
timex[l_] := Module[{i =
1, ans = {}}, While[i < Length[l], Append[ans, {l[[i,
1]], l[[i, 2]]}]; i = i + 1]; Return[ans]];

This doesn't work and returns an empty list {}.

I'm going to use python + reportlab now ....

```

• Prev by Date: Problem with FullSimplify in Version 5: Rationals are converted to Reals
• Next by Date: Re: Palette rememberance
• Previous by thread: Re: Extracting elements of lists