In this Python list program, we will take a user input as a list and insert sublist into the list at specific index with the help of the below-given steps.
Insert sublist in a list:
Steps to solve the program
- Take a list as input.
- Insert a sublist into the given list at a specific index using the insert() function.
- Print the list to see the output.
#Input list
list1 = [4, 6, 8, 2, 3, 5]
#Inserting list
list1.insert(3,[5, 2, 6])
#Printing output
print(list1)
Output :
[4, 6, 8, [5, 2, 6], 2, 3, 5]
Related Articles
Python program to calculate the bill per fruit purchased from a given fruits list.
Python program to calculate percentage from a given mark list, the max mark for each item is 100.
Python program to get the list of all palindrome strings from the given list.
Python program to flatten a given nested list structure.
Python program to convert tuples in the list into a sublist.
Python program to create a dictionary from a sublist in a given list.