Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

Re: How Do You Reduce Multiple Elements in a List?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33887] Re: How Do You Reduce Multiple Elements in a List?
  • From: dennisw555 at aol.com (DennisW555)
  • Date: Sun, 21 Apr 2002 06:14:24 -0400 (EDT)
  • References: <a9r3ve$ltc$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

>Given a list of integers that generally contains the same number many times,
>I'd like to reduce it to a list that just gives me the number/count pairs.
>For example, I'd like to convert the list
>   {1, 1, 1, 1, 1, 2, 2, 2, 4, 4, 4, 4, 4, 4}
>into
>   {{1,5}, {2,3}, (4,6}}

Try

Map[{First#],Length[#]}&,Split[list]]

If you want all the numbers on ascending order use

Map[{First#],Length[#]}&,Split[Sort[list]]]

Dennis


  • Prev by Date: References to subjects of Mathematica notebooks
  • Next by Date: Start-up window size saving
  • Previous by thread: Re: How Do You Reduce Multiple Elements in a List?
  • Next by thread: Re: How Do You Reduce Multiple Elements in a List?