0

What am I trying to do? I want to put multiple elements to the same position in a list without discarding the previously appended ones.

I know that if mylist.append("something")is used, the appended elements will be added every time to the end of the list.

What I want it's something like this mylist[i].append("something"). Of course that doesn't work, but it's just the idea.

I tried to append a list to another list, but that didn't work neither because the append function can't handle lists.

Is there any way to append stuff to a specific zone in a list?

Marko
  • 407
  • 1
  • 7
  • 19
  • Yes, that topic is similar. I searched pretty much before posting and also It didn't showed up when asking, sorry. – Marko Mar 26 '17 at 08:47

1 Answers1

4

You may use list slicing and concatenation as:

lst = [1, 2, 3, 6, 7, 8]
new_lst = [4, 5]
position = 3
combined_lst = lst[:position] + new_lst + lst[position:]
ZdaR
  • 22,343
  • 7
  • 66
  • 87