       Re: extracting elements from a list of lists

• To: mathgroup at smc.vnet.net
• Subject: [mg5827] Re: [mg5811] extracting elements from a list of lists
• From: "w.meeussen" <w.meeussen at solair4b.eunet.be>
• Date: Thu, 23 Jan 1997 03:19:30 -0500
• Sender: owner-wri-mathgroup at wolfram.com

```At 00:44 22-01-97 -0500, you wrote:
>Hi,
>
>Suppose I have lists within a list, like:
>
>  myList = {{a,b}, {c,d}}
>
>and I want to extract some element (let's say the d).
>I can request:
>
>  myList[[2,2]].
>
>Now suppose what I have the index of the element as
>the list {2,2}.  Then I can do:
>
>  Fold[Part, myList, {2,2}]
>
>Is it correct to suppose that it will first return the
>2nd sublist, and then extract the second element from it?
>How efficient is it?  This may be a crucial point
>if I have long lists, I think.  Then isn't there a
>better way of doing this?

hi Olivier,

In:=
Fold[Part, myList, {2,2}]
Out=
d

as you can see by checking the steps:
In:=
FoldList[Part, myList, {2,2}]
Out=
{{{a,b},{c,d}}
,{c,d}
,d}

but The Book as good documentation on myList [[2,2]]:
In:=
Part[myList,2,2]
Out=
d

In:=
target={1,3,2}
Out=
{1,3,2}
In:=
longer=
{
{{a,b,c},{d,e,f},{g,h,i}},{{j,k,l},{m,n,o},{p,q,r}}
}
Out=
{{{a,b,c},{d,e,f},{g,h,i}},{{j,k,l},{m,n,o},{p,q,r}}}
In:=
Part[longer,Sequence@@target]
Out=
h

the trick is in Sequence[]

Dr. Wouter L. J. MEEUSSEN
w.meeussen at solair4b.eunet.be

```

• Prev by Date: Re: HTML conversion question
• Next by Date: Float32 from a file
• Previous by thread: extracting elements from a list of lists
• Next by thread: Re: extracting elements from a list of lists