8. Write a python program to insert a new number before a specified element of array_a as provided in the following output.
The output is:
array_a = array('i', [0, 1, 2, 3, 4, 5, 7, 8, 5, 9, 10, 5])
new number: 8
insert the new number before number: 6
Expected Answer:
The initial array: array('b', [0, 1, 2, 3, 4, 5])
Insert new value 8 before number 5:
New array: array('b', [0, 1, 2, 3, 4, 8, 5])
Sample Answer:
from array import * array_a = array('b', [0, 1, 2, 3, 4, 5]) print("The initial array: "+str(array_a)) print("Insert new value 8 before number 5:") array_a.insert(5, 8) print("New array: "+str(array_a))
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)