KnowledgeBoat Logo
|

Informatics Practices

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.

Python List Manipulation

8 Likes

Answer

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)

Output

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]

Answered By

3 Likes


Related Questions