Error when trying to get the union, intersection and difference in a set
<p>As the title says, I am getting an error in my code here:</p>

<pre><code>#!/usr/bin/python3

import random

A = random.sample(set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 5)

B = random.sample(set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 5)


print(A | B)

print(A &amp; B)

print(A - B)
</code></pre>

<p>The error I'm getting is <code>TypeError: unsupported operand type(s) for |: 'list' and 'list'.</code> I have also tried <code>random.sample(range(10), 5)</code>, which still does not work.</p>

<p>Is there anything I'm doing wrong?</p>

<p>So, as error says, function: </p>

<pre><code>random.sample  
</code></pre>

<p>returns <strong>list</strong> object not <strong>set</strong> , try convert them like this :</p>

<pre><code>A = set(random.sample(range(1,10), 5))
</code></pre>

python python-3.x