Extracting elements of lists
- To: mathgroup at smc.vnet.net
- Subject: [mg45458] Extracting elements of lists
- From: sashan <nothing at important.com>
- Date: Fri, 9 Jan 2004 05:20:26 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
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 ....
- Follow-Ups:
- Re: Extracting elements of lists
- From: "Sseziwa Mukasa,,(978) 536-2359" <mukasa@jeol.com>
- Re: Extracting elements of lists