Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'list manipulation ?' topicStudent Support Forum > General > "list manipulation ?"

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
Author Comment/Response
Peter Pein
07/08/13 04:46am

Hi,

another Approach (if 'b,c,d' is not at the same place in each sublist) would be:

(* construct input *)
In[1]:= list =
NestList[RotateLeft, ToExpression /@ CharacterRange["a", "g"], 6]

Out[1]=
{{a, b, c, d, e, f, g},
{b, c, d, e, f, g, a},
{c, d, e, f, g, a, b},
{d, e, f, g, a, b, c},
{e, f, g, a, b, c, d},
{f, g, a, b, c, d, e},
{g, a, b, c, d, e, f}}

(* distinguishable replacements *)
In[2]:= repl = Array[p[#1] &, {7, 1}]

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

(* the replacement-function for one sublist: *)
In[3]:= f[l1_List, l2_List, seq___] :=
l1 /. {start___, seq, rest___} :>
{start, Sequence @@ l2, rest}

(* apply that func. to the input(s)*)
In[4]:= MapThread[f[#1, #2, b, c, d] &, {list, repl}]

Out[4]=
{{a, p[1], e, f, g},
{p[2], e, f, g, a},
{c, d, e, f, g, a, b},
{d, e, f, g, a, b, c},
{e, f, g, a, p[5]},
{f, g, a, p[6], e},
{g, a, p[7], e, f}}

Peter

URL: ,

Subject (listing for 'list manipulation ?')
Author Date Posted
list manipulation ? augustus 07/07/13 10:32am
Re: list manipulation ? Bill Simpson 07/07/13 8:35pm
Re: list manipulation ? Peter Pein 07/08/13 04:46am
Re: list manipulation ? augustus 07/08/13 12:50pm
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic