Python Program to remove an element from a list (Using list comprehension)

bookmark

# Python program to remove an element from a list using the list comprehension  
  
my_list = [1, 2, 3, 4, 5]  
my_list = [x for x in my_list if x != 3]  # Removes the element 3 from the list  
print(my_list)     


Output:

[1, 2, 4, 5]