delete element in list python

Description

Python Program to get an element and delete the element from list.
Input:
5
5 7 9 3 1
9
Output:
5 7 3 1

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)
            

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]