Re: Partitioning lists

• To: mathgroup at smc.vnet.net
• Subject: [mg20482] Re: Partitioning lists
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Wed, 27 Oct 1999 02:04:48 -0400
• References: <7v3dfq\$63d@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```DIAMOND Mark <noname at noname.com> wrote in message
news:7v3dfq\$63d at smc.vnet.net...
> 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
>

We could  use

Table[Split[a, #1 != i &], {i, Length[a] - 1}] // Timing

But this is much slower because of all  the testing needed.

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

```

• Prev by Date: Re: StylePrint problem
• Next by Date: Re: Basic Laplace Transforms
• Previous by thread: Re: Partitioning lists
• Next by thread: Re: Partitioning lists