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>It sounds like this is a homework problem, especially since you can't use <code>.remove</code>.</p>

<p>Given that, your teacher probably wants you to take a manual approach that looks something like this:</p>

<ol>
<li>Create a new list</li>
<li>For each item in the previous list...

<ol>
<li>If it's not the value you want to filter out, <code>.append</code> it to your new list</li>
</ol></li>
<li>Return your new list</li>
</ol>

<p>(mouseover if you don't want to write the code yourself)</p>

<blockquote class="spoiler">
  <p><pre>
def remove(list1, num):
    new_list = []
    for item in list1:
        if item != num:
            new_list.append(item)
    return new_list</pre></p>
</blockquote>

python loops for-loop