Python: Combining two lists and removing duplicates in a functional programming way
<p>I'm trying to write a function that would combine two lists while removing duplicate items, but in a pure functional way.
For example:</p>

<pre><code>a = [1,2,2]
b = [1,3,3,4,5,0]
union(a,b) --&gt; [1,2,3,4,5,0]
</code></pre>

<p>The imperative form of the code would be:</p>

<pre><code>def union(a,b):
    c = []
    for i in a + b:
        if i not in c:
            c.append(i)
    return c
</code></pre>

<p>I've tried several approaches, but couldn't find a way to do that without using a loop to go over the items - what am I missing?</p>

<p>How about </p>

<pre><code>&gt;&gt;&gt; x = [1,2,3]
&gt;&gt;&gt; y = [1,3,5,7,9]
&gt;&gt;&gt; list(set(x).union(set(y)))
</code></pre>

python functional-programming