# Lists and for loops

**URL:** <https://forum.codewithmosh.com/t/lists-and-for-loops/15708>\
**Category:** Uncategorized\
**Created:** [October 7, 2022, 10:09am UTC](https://forum.codewithmosh.com/t/lists-and-for-loops/15708 "2022-10-07T10:09:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MariaK](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@MariaK](https://forum.codewithmosh.com/u/MariaK)\
**Post date:** [October 7, 2022, 10:09am UTC](https://forum.codewithmosh.com/t/lists-and-for-loops/15708/1 "2022-10-07T10:09:40Z")

</div>

Hi everyone .Here is again a python list problem I am stuck on this once again 🙂

```auto
my_list = [1, 2]

for v in range(2):
    my_list.insert(-1 , my_list[v])

print(my_list)

```

Now I though the answer would be [1,1,2,2,]  
But NO!  
the answer is [1,1,1,2]  
Can someone pls explain how?

---

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [October 7, 2022, 2:16pm UTC](https://forum.codewithmosh.com/t/lists-and-for-loops/15708/2 "2022-10-07T14:16:24Z")

</div>

The answer to your question is actually on StackOverflow: [python - Array: Insert with negative index - Stack Overflow](https://stackoverflow.com/questions/53932704/array-insert-with-negative-index)

Basically insert at -1 inserts the item _before_ the position specified (so before the last element). Also remember the list is being mutated as you go.

So the first iteration of the loop results in: `[1, 1, 2]` because the element at index 0 is 1 and we insert it before the last element. The second iteration results in `[1, 1, 1, 2]` because the new value at index 1 is now 1 and we insert it before the last element.
