Use the Python insert() method to insert a list into the list at index. This method Insert an item at the specified index.
Set the index for the first parameter and the item to be inserted for the second parameter.
Python example insert list into a list at index
Simple example code inserts a list at the specified index (position). Let’s insert a list of index position 1.
list1 = [1, 2, 3] list2 = ["A", "B", "C"] list1.insert(1, list2) print(list1)
Note: The index at the beginning is
0 . For negative values,
-1 means one before the end.
Do comment if you have any doubts and suggestions on this Python list tutorial.
Note: IDE: PyCharm 2021.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.