removing a number from a list
<p>I'm stuck on a part of a looping question. I have to remove from list1 all instances of "number". So lets say list1 is (1,2,3) and num is 2. The list I would have to return would be (1,3)</p>

<pre><code>def remove(list1,num)

    list1=list1
    num = num
</code></pre>

<p>This is what is given. 
So far, I have this:</p>

<pre><code>def remove(list1,num)

list1=list1

num=num

if num in list1:
</code></pre>

<p>This is where I'm stuck because I don't know how to say in coding "remove num from list" 
I am not allowed to use .remove either. </p>

<p>Would appreciate the help.</p>

<p>To go with pure loops and delete with list index:</p>

<pre><code>#!/usr/bin/env python
from __future__ import print_function

def remove(item, old_list):
    while True:
        try:
            # find the index of the item
            index = old_list.index(item)
            # remove the item found
            del old_list[index]
        except ValueError as e:
            # no more items, return
            return old_list

a_list = [1, 2, 3, 2, 1, 3, 2, 4, 2]
print(remove(2, a_list))
</code></pre>

<p>If possible, of course, you should use list comprehension, which is pythonic and much easier!</p>

python loops for-loop