# Construct / re-arrange some lists?

**URL:** <https://community.wolfram.com/t/construct-re-arrange-some-lists/11161>\
**Category:** Questions\
**Tags:** symbolic-computations\
**Created:** [August 29, 2017, 12:12pm UTC](https://community.wolfram.com/t/construct-re-arrange-some-lists/11161 "2017-08-29T12:12:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreasmaier82](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@andreasmaier82](https://community.wolfram.com/u/andreasmaier82)\
**Post date:** [August 29, 2017, 12:12pm UTC](https://community.wolfram.com/t/construct-re-arrange-some-lists/11161/1 "2017-08-29T12:12:19Z")

</div>

Hi all,

I am trying to re-arranging some lists with some variables. Following code:

```
lista = {{a, b, c}, {d, e, f, g}};
listb = {{h, i, j}, {k, l, m}};
sol = Flatten[Outer[List, lsta, lstb], 3]

```

With my Flatten[…] command I can’t get unfortunately the right re-arangement.  
My goal is that the first bracket of lista shall only be processed with the first bracket of listb:

```
{{a, h}, {a, i}, {a, j}, {b, h}, {b, i}, {b, j}, {c, h}, {c, i}, {c, 
  j}}

```

as well as only the 2. bracket of lista with the 2. bracket of list b and so on…

```
{{d, k}, {d, l}, {d, m}, {e, k}, {e, l}, {e, m}, {f, k}, {f, l}, {f, 
  m}, {g, k}, {g, l}, {g, m}}

```

Do you have some ideas or hints how I can achieve that?

---

<div class="post-metadata">

**Author:** ![gdelfino](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/gdelfino/32/41294_2.png) [@gdelfino](https://community.wolfram.com/u/gdelfino)\
**Post date:** [August 29, 2017, 12:57pm UTC](https://community.wolfram.com/t/construct-re-arrange-some-lists/11161/2 "2017-08-29T12:57:51Z")

</div>

I’m not sure if this is what you are asking:

```
In[1]:= Map[Flatten[Outer[List,lista,#],2]&,listb]

Out[1]= {{{a,h},{a,i},{a,j},{b,h},{b,i},{b,j},{c,h},{c,i},{c,j},{d,h},{d,i},{d,j},{e,h},{e,i},{e,j},{f,h},{f,i},{f,j},{g,h},{g,i},{g,j}},
         {{a,k},{a,l},{a,m},{b,k},{b,l},{b,m},{c,k},{c,l},{c,m},{d,k},{d,l},{d,m},{e,k},{e,l},{e,m},{f,k},{f,l},{f,m},{g,k},{g,l},{g,m}}}

```

---

<div class="post-metadata">

**Author:** ![andreasmaier82](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@andreasmaier82](https://community.wolfram.com/u/andreasmaier82)\
**Post date:** [August 29, 2017, 1:47pm UTC](https://community.wolfram.com/t/construct-re-arrange-some-lists/11161/3 "2017-08-29T13:47:52Z")

</div>

Hi Gustavo,

thanks for your help. Unfortunalety not. It is quite he same…For example

```
{d, e, f, g} 

```

shall only be processed with

```
{k, l, m}

```

and that results

```
{{d, k}, {d, l}, {d, m}, {e, k}, {e, l}, {e, m}, {f, k}, {f, l}, {f, 
  m}, {g, k}, {g, l}, {g, m}}

```

I will keep trying…

---

<div class="post-metadata">

**Author:** ![vaungureanu](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/vaungureanu/32/23129_2.png) [@vaungureanu](https://community.wolfram.com/u/vaungureanu)\
**Post date:** [August 29, 2017, 1:57pm UTC](https://community.wolfram.com/t/construct-re-arrange-some-lists/11161/4 "2017-08-29T13:57:58Z")

</div>

What about applying the function **Table[]**:

```
In[1]:= lista = {{a, b, c}, {d, e, f, g}, {n, o}};
listb = {{h, i, j}, {k, l, m}, {s, t, p, q}};

In[3]:= Flatten[
Table[{lista[[ii, jj]], listb[[ii, kk]]}, {ii, Length[lista]}, {jj, 
Length[lista[[ii]]]}, {kk, Length[listb[[ii]]]}], 2]

Out[3]= {{a, h}, {a, i}, {a, j}, {b, h}, {b, i}, {b, j}, {c, h}, {c,i}, {c, j},
{d, k}, {d, l}, {d, m}, {e, k}, {e, l}, {e, m}, {f, k}, {f, l}, {f, m}, {g, k}, {g, l}, {g, m},
{n, s}, {n, t}, {n, p}, {n, q}, {o, s}, {o, t}, {o, p}, {o, q}}

```

---

<div class="post-metadata">

**Author:** ![gdelfino](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/gdelfino/32/41294_2.png) [@gdelfino](https://community.wolfram.com/u/gdelfino)\
**Post date:** [August 30, 2017, 1:18pm UTC](https://community.wolfram.com/t/construct-re-arrange-some-lists/11161/5 "2017-08-30T13:18:10Z")

</div>

How about this:

```
In[1]:= Thread[f[lista, listb]] /. f[a_List, b_List] :> Flatten[Outer[List, a, b], 1]

Out[1]= {{{a,h}, {a,i}, {a,j}, {b,h}, {b,i}, {b,j}, {c,h}, {c,i}, {c,j}},
         {{d,k}, {d,l}, {d,m}, {e,k}, {e,l}, {e,m}, {f,k}, {f,l}, {f,m}, {g,k}, {g,l}, {g,m}}}

```

---

<div class="post-metadata">

**Author:** ![andreasmaier82](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@andreasmaier82](https://community.wolfram.com/u/andreasmaier82)\
**Post date:** [September 1, 2017, 8:52am UTC](https://community.wolfram.com/t/construct-re-arrange-some-lists/11161/6 "2017-09-01T08:52:26Z")

</div>

Hi,  
many thanks @ Valeriu and Gustavo!

That’s what I have searched for…
