CBSE Class 11 Computer Science
Question 59 of 82
Lists in Python — Question 24
Back to all questions 24
Question Write a program to create a list of elements. Input an element from the user that has to be inserted in the list. Also, input the position at which it is to be inserted.
list1 = eval(input("Enter list: "))
new_element = int(input("Enter the element to be inserted: "))
position = int(input("Enter the position at which the element should be inserted: "))
list1.insert(position, new_element)
print("Updated list:", list1)Enter list: [23, 6, 7, 8, 9]
Enter the element to be inserted: 15
Enter the position at which the element should be inserted: 3
Updated list: [23, 6, 7, 15, 8, 9]