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.
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]
Related Questions
Write a program to read a list of n integers and find their median.
Note: The median value of a list of values is the middle one when they are arranged in order. If there are two middle values, then take their average.
Hint: Use an inbuilt function to sort the list.
Write a program to read a list of elements. Modify this list so that it does not contain any duplicate elements, i.e., all elements occurring multiple times in the list should appear only once.
Write a program to read elements of a list and do the following:
(a) The program should ask for the position of the element to be deleted from the list and delete the element at the desired position in the list.
(b) The program should ask for the value of the element to be deleted from the list and delete this value from the list.
Write a program that accepts elements of a list S and adds all the odd values and displays the sum.