A new method to insert a central list of python list:

>>> a,b
([1, 2, 3, 4, 7, 8, 9], [5, 6])
>>> a
[1, 2, 3, 4, 7, 8, 9]
>>> b
[5, 6]
>>> a.insert(3,b)
>>> a
[1, 2, 3, [5, 6], 4, 7, 8, 9]
>>> 

Conventional methods, as described above, is generated using a sequence insert

new plan:

a=[1,2,3,4,9,10,11]
b=[4,5,6,7,8,9]
print(a,b)
def insert_array(a,b): 
       c=[]
       for i in range(0,len(a)-1):
             if a[i]==b[0]:
               start=i
             elif a[i]==b[len(b)-1]: 
                end=i    
       for i in range(0,start):
            c.append(a[i])
       for j in b:
            c.append(j)
       for j in range(end+1,len(a)):
            c.append(a[j])
       return c
c=insert_array(a,b)
print(c)







Output:

([1, 2, 3, 4, 9, 10, 11], [4, 5, 6, 7, 8, 9])
([1, 2, 3, 4, 9, 10, 11], [4, 5, 6, 7, 8, 9], 3, 4)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

Guess you like

Origin blog.csdn.net/weixin_42528089/article/details/90410357