# Expanding a list

**URL:** <https://community.wolfram.com/t/expanding-a-list/6022>\
**Category:** Questions\
**Tags:** mathematica\
**Created:** [June 23, 2015, 11:01pm UTC](https://community.wolfram.com/t/expanding-a-list/6022 "2015-06-23T23:01:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahautot](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@ahautot](https://community.wolfram.com/u/ahautot)\
**Post date:** [June 23, 2015, 11:01pm UTC](https://community.wolfram.com/t/expanding-a-list/6022/1 "2015-06-23T23:01:57Z")

</div>

Hello,  
can somebody help me :

Given a list of Integers, say v={5, 4, 0, 6}  
and a list of allowed positions, say pos={1, 3} (but it might be {1, 2, 3} or {2} or …),  
I need an automatic expansion of v equivalent to, say : Table[{i, 4, j, 6},{i,2},{j,2}] where i and j occupy the positions defined by pos.  
Please remember that pos migth be {1, 2, 3} so that i,j and k would be needed in that case.  
Thanks for the help !  
André

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [June 24, 2015, 9:47am UTC](https://community.wolfram.com/t/expanding-a-list/6022/2 "2015-06-24T09:47:05Z")

</div>

An attempt:

```
v = {5, 4, 0, 6};
pos = {1, 3};
vars = Table[i[k], {k, Length[pos]}];
Table[Evaluate@ReplacePart[v, Thread[pos -> vars]], 
 Evaluate[Sequence @@ Map[{#, 2} &, vars]]]

```

---

<div class="post-metadata">

**Author:** ![ahautot](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@ahautot](https://community.wolfram.com/u/ahautot)\
**Post date:** [June 24, 2015, 11:27am UTC](https://community.wolfram.com/t/expanding-a-list/6022/3 "2015-06-24T11:27:52Z")

</div>

Thanks a lot, it fixes the question neatly !
