MathGroup Archive 2007

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

Search the Archive

Partition a list into sublists of unequal size

  • To: mathgroup at
  • Subject: [mg83919] Partition a list into sublists of unequal size
  • From: antf <anthonyfox at>
  • Date: Tue, 4 Dec 2007 04:29:39 -0500 (EST)


I have a list that looks like the following:


I then find the positions of the 1s in the list:

positions = Flatten@Position[list,1]


I then want to partition a third list into sublists so that the first
sublist is from index 1;;1, the second sublist is from index 2;;4, the
third sublist is from index 5;;7, the fourth sublist is just element
8, etc.

Currently, I use Partition on the positions sublist with overlap as



I then use this list to partition the target list by Mapping Take to
each element of this list and adjusting the first index appropriately.

I am sure there must be a simpler way to do this.  Can anyone tell me
how to do this operation?


  • Prev by Date: ContourLabel placement
  • Next by Date: Re: Re: Hiding number cell
  • Previous by thread: Re: ContourLabel placement
  • Next by thread: Re: Partition a list into sublists of unequal size