Hii guys ,i have been trying to solve a problem where from a given list you have to remove a given element. list1=[0,1,2,2,3,0,4,2], remove_element=2 : 

  

      def fun(list1,remove_element):
            if len(list1)==0:
                return 0
            for i in range(len(list1)):
                if remove_element==list1[i]:
                    list1.remove(remove_element)
            return list1

here is the error i get:
    
 
<pre>
    Traceback (most recent call last):
      File "<pyshell#205>", line 1, in <module>
        print(fun(list1,remove_element))
      File "<pyshell#204>", line 5, in fun
        if remove_element==list1[i]:
    IndexError: list index out of range
</pre>

  


