condensing multiple if statements in python
<p>I'm trying to write a function to check if an object is found in multiple lists and to remove the object from any list its found in. I want to know if there is a way to make it cleaner or smarter using some form of generic variable where you predefine the format or something along those lines. 
my code in its ugly form:</p>

<pre><code>def create_newlist(choice):

    if choice in list_a:
        list_a.remove(choice)
    if choice in list_b:
        list_b.remove(choice)
    if choice in list_c:
        list_c.remove(choice)
    if choice in list_d:
        list_d.remove(choice)
    if choice in list_e:
        list_e.remove(choice)
</code></pre>

<p>What I'm hoping for is something like:</p>

<pre><code>if choice in list_x:
   list_x.remove(choice)
</code></pre>

<p>I would like it to work for each list, would I need to loop through? any suggestions would be great! I have the workaround but I would love to learn a more elegant way of coding this!</p>

<h3>In a one-liner</h3>

<p>If you use <code>some_list.remove(item)</code>, only the first found match of <code>item</code> is removed from the list. Therefore, it depends if the lists possibly include duplicated items, which (all) need to be removed:</p>

<h3>1. If all items in all lists are unique</h3>

<pre><code>list1 = ["a", "b" , "c", "d"]
list2 = ["k", "l", "m", "n"]
list3 = ["c", "b", "a", "e"]

[l.remove("a") for l in [list1, list2, list3] if "a" in l]

print(list3)
&gt; ["c", "b", "e"]
</code></pre>

<p><em>However</em> </p>

<h3>2. If one or more lists possibly includes duplicated items</h3>

<p>In that case <code>itertools</code>' <a href="https://docs.python.org/3/library/itertools.html#itertools.filterfalse" rel="nofollow">filterfalse()</a> will come in handy:</p>

<pre><code>from itertools import filterfalse

def remove_val(val, lists):
    return [list(filterfalse(lambda w: w == val, l)) for l in lists]

l1 = ["a", "b" , "c", "d"]
l2 = ["k", "l", "m", "n"]
l3 = ["a", "c", "b", "a", "a", "e"]

newlists = remove_val("a", [l1, l2, l3])
</code></pre>

<p>Then the test:</p>

<pre><code>print(newlists)
&gt; [['b', 'c', 'd'], ['k', 'l', 'm', 'n'], ['c', 'b', 'e']]
</code></pre>

python list loops if-statement