MathGroup Archive 2008

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

Search the Archive

Re: Re: Intersection of lists of lists based on the first term

On Fri, Apr 11, 2008 at 9:46 PM, Stern <nycstern at> wrote:
> Thank you, but I think I am not understanding the second bit -- what is
> (isCommon[#] = True) & /@ timeStampsInCommon supposed to achieve other than
> a list of True equal to the length of timeStampsInCommon in every case?

Perhaps I should have written it as

Scan[(isCommon[#] = True) &, timeStampsInCommon]

to emphasize that the function (isCommon[#] = True) & is only invoked
for its side effects, i.e. defining new DownValues for the symbol

This will set the value of isCommon[ ... ] to True for each of the
elements in timeStampsInCommon.  Thus, isCommon[elem] is equivalent to
MemberQ[timeStampsInCommon, elem], but it is much faster if
timeStampsInCommon has many elements (because Mathematica will use a
hash table for looking up elements instead of simply iterating through
timeStampsInCommon).  Note that isCommon[] needs to be Clear[]ed after
each use (a better solution is encapsulating the whole thing into a
Module where isCommon is a local symbol).

  • Prev by Date: Re: Tilted decimals on the x-axis to avoid overlapping
  • Next by Date: Re: Appearance of DendrogramPlot
  • Previous by thread: Re: Intersection of lists of lists based on the first term
  • Next by thread: Grade calculation tool for students....