delete element in list python
Python Program to get an element and delete the element from list.
Sample Input 1:
5 5 7 9 3 1 9
Sample Output 1:
5 7 3 1
Program or Solution
l=list(map(int,input("Enter Numbers:").split()))
e=int(input("Enter the element to delete"))
for i in range(0,len(l)):
if(l[i]==e):
for j in range(i,len(l)-1):
l[j]=l[j+1]
l[j+1]=None
print(l)
Program Explanation
visit every location in the list if current element in list l[i] is equal to the element which is to be deleted.
Then move all the elements located after i to its previous position using: l[i] = l[i+1]
Comments
Related Programs
- list input in python
- sum of list in python | without using built-in function
- Average of list in python | without using built-in function
- linear search in python
- largest element in the list python | without using built-in function
- smallest element in the list python | without using built-in function
- Print all the numbers which are less than given key element from a given list.
- Revese the elements in list python
- Reverse the first half of list elements in python
- Reverse the second half of list elements in python
- list sort python
- list sort descending order python
- Python Program to sort half of the list elements in ascending order and next half in descending order.
- merging two lists in python
- Python Program to replace every element with the greatest element on right side
- circular list rotation in python
coming Soon
coming Soon