Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Occurrences in Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106373] Re: [mg106350] Occurrences in Mathematica
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Mon, 11 Jan 2010 05:28:04 -0500 (EST)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <201001100828.DAA05428@smc.vnet.net>
  • Reply-to: murray at math.umass.edu

Here's one way, via an example:

   lis = RandomChoice[Characters["abcdefghijklmnopqrstuvwxyz"], 50];

   Select[Union[lis], Count[lis, #] == 2 &]

Your results will vary according to what RandomChoice gives you. But the 
code does exactly what you asked: it selects (Select) from the unique 
elements of the list (Union[lis]) those elements for which the Count of 
their appearances in the list is 2.

I make no claims for the efficiency of the code. That may depend upon 
the length and perhaps even the elements of your list, among other things.

On 1/10/2010 3:28 AM, George wrote:
> Hi,
>
> I have a very big list of elements and I need Mathematica to give me
> only those elements which occure only once...
>
> Could anybody advise me please how to write the code for that?
>
> Thks much
> George
>

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: Occurrences in Mathematica
  • Next by Date: Re: Radicals simplify
  • Previous by thread: Re: Occurrences in Mathematica
  • Next by thread: Re: Occurrences in Mathematica