MathGroup Archive 1995

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

Search the Archive

Re: [Q] {a,b,c}->{{a,b},{b,c}}

Hello Mma-users,

I while ago I posted a question here.
I wanted to know how I could make {{a,b},{b,c}} out of {a,b,c} for instance,
but then for any list.
I received a number of different solutions that I shall mention in this
mail. I've let them all solve the problem for the list : Range[10^4] and
I include the timing to each solution.

2.64 Second

Map[ Module[ {qux = absolutelyNothing},
             (If[ qux === absolutelyNothing,
                  qux = #; Sequence @@ {},
                  {qux, qux = #} ])& ], list ]
9.51 Second

Transpose[ { Drop[ list, -1 ], Drop[ list, 1 ] } ]
1.81 Second

r[ {x__} ] := Map[ Pattern[ #, Blank[] ]&, {x} ] ->
              Table[ { {x}[[i]], {x}[[i+1]] }, {i, 1, Length[ {x} ] - 1 } ]
x /. r[x]
33.94 Second

Not all responses are included, some didn't do exactly what I wanted or I
couldn't get the answer with them. Some minor changes have been made in a

Thank you all for replying to my question, it's been of great help.


Bart van der Zwet
Student Mathematics
Eindhoven University of Technology
The Netherlands
e-mail : B.W.v.d.Zwet at

  • Prev by Date: Question about thread
  • Next by Date: Re:Puzzle
  • Previous by thread: Re: [Q] {a,b,c}->{{a,b},{b,c}}
  • Next by thread: Re: Re: [Q] {a,b,c}->{{a,b},{b,c}}