Skip to content Skip to sidebar Skip to footer

How Do I Insert A List Into Another List?

I have two lists: A = [1,2,3] B = [4,5,6] Is there an elegant way to insert B into A at an arbitrary position? Hypothetical output: [1,4,5,6,2,3] Obviously I could iterate throug

Solution 1:

A[1:1] = B

A will be [1, 4, 5, 6, 2, 3]


Solution 2:

def insert(outer, inner, pos):
  outer[pos:pos] = inner

Post a Comment for "How Do I Insert A List Into Another List?"