MathGroup Archive 1999

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

Search the Archive

Re: Partitioning lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20561] Re: Partitioning lists
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sat, 30 Oct 1999 00:14:08 -0400
  • References: <7v3dfq$63d@smc.vnet.net> <7vao13$a3l$8@dragonfly.wolfram.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Seth,

Simpler:

ReplaceList[{a, b, c, d, e, f}, {x__, y__} -> {{x}, {y}}]


{{{a}, {b, c, d, e, f}}, {{a, b}, {c, d, e, f}}, {{a, b, c}, {d, e, f}},
{{a,
      b, c, d}, {e, f}}, {{a, b, c, d, e}, {f}}}

but slower than Mark's original.

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



Seth Chandler <SChandler at uh.edu> wrote in message
news:7vao13$a3l$8 at dragonfly.wolfram.com...
> I am not sure this is any better, but the following also works
>
>
> Union[DeleteCases[
>     ReplaceList[{a, b, c, d, e, f}, {x___, y___} -> {{x}, {y}}], {},
>     Infinity]]
>
>
> 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
> >
> >
> >
> >
> >
>
>
>
>
>



  • Prev by Date: Re: Version 3.0 unstable?
  • Next by Date: Re: Urgent Help needed
  • Previous by thread: Re: Partitioning lists
  • Next by thread: Re: Partitioning lists