Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Partitioning a list into unequal partitions

  • To: mathgroup at
  • Subject: [mg47686] Re: Partitioning a list into unequal partitions
  • From: Mark Fisher <mark at>
  • Date: Thu, 22 Apr 2004 02:38:30 -0400 (EDT)
  • References: <c5gfdp$an0$>
  • Sender: owner-wri-mathgroup at

For what it's worth, here's my way:

UnevenPartition::usage = "UnevenPartition[list, lengths] returns the 
list partitioned into groups with the specified successive lengths."

UnevenPartition[list_, lengths_] :=
	First@Fold[Regroup, {{}, list}, lengths]

Regroup[{a_, b_}, n_] := {Append[a, Take[b, n]], Drop[b, n]}

UnevenPartition[Range[10], Range[4]]


DIAMOND Mark R. wrote:
> Could someone please show me a simple (non-procedural) way of partitioning a
> list into 1,2,3 ... n disjoint sublists, where the length of the list is
> guaranteed to be correct (i.e. n*(n+1)/2)
> I can't see a way, and yet I'm sure there *must* be a one-liner using Fold.
> Cheers
> Mark R. Diamond

  • Prev by Date: Re: Dashing option and Plot
  • Next by Date: Re: Simplify using custom function
  • Previous by thread: Re: Partitioning a list into unequal partitions
  • Next by thread: Regarding a 3D plot in mathematica