insert many numbers to a list, a second method.

飛飛 benph at sina.com
Tue Jan 5 08:36:32 EST 2016



--------------------------------
l = list(range(0,12))
numbers = [5,3,2,7]         #insert numbers at 5th position.
list1 = list(range(5,9))
list2 = list(range(0,5))
list2.extend(numbers)     #
for i in list1:
    l.insert(i,list2[i])
print(l)------>           l =  [0, 1, 2, 3, 4, 5, 3, 2, 7, 5, 6, 7, 8, 9, 10, 11]


More information about the Python-list mailing list