MathGroup Archive 1997

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

Search the Archive

Re: extracting elements from a list of lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg5834] Re: [mg5811] extracting elements from a list of lists
  • From: Francisco Edmundo de Andrade <edmundo at lia.ufc.br>
  • Date: Tue, 28 Jan 1997 03:42:58 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

On Wed, 22 Jan 1997, Olivier Georg 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?
> 
> Olivier
> -- 
> -------------------------------------------------------------------
> | Olivier Georg      \__  e-mail:    Olivier.Georg at studi.epfl.ch  |
> | Rte de Chailly 159    \__  home:   http://diwww.epfl.ch/~ogeorg |
> | 1814 La Tour-de-Peilz    \__  tel: +41 21 944 15 42             |
> ------------------------------\__----------------------------------
> | On ne peut pas tuer le temps   \__                              |
> | Sans blesser un peu l'eternite    \__       ________    __o     |
> | ( As if you could kill time  )       \__      _____   _`\<,_    |
> | ( without injuring eternity. )          \__      ___ (_)/ (_)   |
> |                   Henry David Thoreau      \                    |
> -------------------------------------------------------------------
> 
> 

Dear Olivier,

I think the follow solution is faster than Fold[Part, myList, {2,2}]: 
  myList[[Sequence @@ {2,2}]]
once that the application of indexes is direct!

With best wishes,

EDMUNDO

(Edmundo's contribuitions 1997)
Universidade Federal do Ceara
   Fortaleza - CE - Brasil
  Departamento de Computacao




  • Prev by Date: Re: Anti-Chop Function
  • Next by Date: Put a list to a file
  • Previous by thread: Re: extracting elements from a list of lists
  • Next by thread: Float32 from a file