MathGroup Archive 2005

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

Search the Archive

Re: element selection

  • To: mathgroup at
  • Subject: [mg53632] Re: [mg53605] element selection
  • From: "David Park" <djmp at>
  • Date: Fri, 21 Jan 2005 06:35:38 -0500 (EST)
  • Sender: owner-wri-mathgroup at


Inner is always a good command to consider when performing operations on the
elements of two equal length lists.

list1 = {1, 4, 5, 10, 11};
list2 = {1, 2, 4, 7, 9};

Inner[If[#1 - #2 < 2, {#1, #2},
      Unevaluated[Sequence[]]] &, list1, list2, List]

Here if the difference of the two elements from each of the lists is less
than 2 we form the couple, otherwise we put in an empty Sequence.
(Sequence[] must be Unevaluated, otherwise it will disappear from the If
statement rather than the resulting list.) The resulting elements are
wrapped in List as specified by the 4th argument of Inner.

David Park
djmp at

From: Bruyndonckx P. [mailto:pbruynd at]
To: mathgroup at

I have two long sorted lists of Integers.  If the difference between a
number in list 1 and a
number in list 2 is less than a certain value, both are selected to create a
couple.  I am
looking for a fast way to go through both lists and extract these elements
to create a new list
of couples.  I tried a number of things, but all of them were rather slow so
I need some expert
advice here.



  • Prev by Date: NDSolve/InterpolatingFunction and vectors
  • Next by Date: compiling python 2.4 mathlink win32
  • Previous by thread: Re: element selection
  • Next by thread: TableForm and MatrixForm