Re: Partitioning lists

• To: mathgroup at smc.vnet.net
• Subject: [mg20509] Re: Partitioning lists
• From: Hans Staugaard <hans.staugaard at get2net.dk>
• Date: Wed, 27 Oct 1999 02:05:05 -0400
• Organization: get2net Internet Kunde
• References: <7v3dfq\$63d@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```DIAMOND Mark wrote:
>
> I would like a function f to split a list as follows
>
> a={1,2,3,4,5,6}
> f[a] =
>   {
>     {{1},{2,3,4,5,6}},
>     {{1,2},{3,4,5,6}},
>     {{1,2,3},{4,5,6}},
>     {{1,2,3,4},{5,6}},
>     {{1,2,3,4,5},{6}}
>   }
>
> I can do this as
>
>       Table[{Take[a, i], Drop[a, i]}, {i, 1, Length[a] - 1}]
>
> but it *looks* as though it is very inefficient. Is it?
> It also looks as though there should be a way of using Partition simply to
> chop a list between positions i and i+1, but
> I cannot see how to do it. Any suggestions?
>
> mark diamond
> no spam email: markd at psy dot uwa dot edu dot au

Here's a suggestion

In[1]:=
t = Range[6]

Out[1]=
{1, 2, 3, 4, 5, 6}

In[2]:=
ReplaceList[t, {a__, b__} -> {{a}, {b}}]

Out[2]=
{{{1}, {2, 3, 4, 5, 6}}, {{1, 2}, {3, 4, 5, 6}}, {{1, 2, 3}, {4, 5,
6}},
{{1, 2, 3, 4}, {5, 6}}, {{1, 2, 3, 4, 5}, {6}}}

I imagine it is not very efficient for large list.

Hans

```

• Prev by Date: Re: About MathML?
• Next by Date: Re: drawing tilted ellipses?
• Previous by thread: Re: Partitioning lists
• Next by thread: Re: Partitioning lists