How to "negate"(?) a list - Python
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/12887398/python-takes-list-and-returns-only-if-negative-value-also-exists-using-set">python takes list and returns only if negative value also exists using set</a>  </p>
</blockquote>



<p>I'm having problems with another homework problem.</p>

<blockquote>
  <p>By using a set, write a method negated(a) that takes a list, a, as an
  argument and returns a list containing only the elements x such that
  -x is also in a</p>
</blockquote>

<p>His example shows that the input is</p>

<blockquote>
  <p>[-6, 8, 7, 3, 2, -9, 1, -3, 2, -4, 4, -8, 7, 8, 2, -2, -7, 0, 1, -9,
  -3, -7, -3, -5, 6, -3, 6, -3, -10, -8]</p>
</blockquote>

<p>and the output is</p>

<blockquote>
  <p>[-6, 8, 7, 3, 2, -3, 2, -4, 4, -8, 7, 8, 2, -2, -7, 0, -3, -7, -3, 6,
  -3, 6, -3, -8]</p>
</blockquote>

<p>I was able to figure out how to do it without using a set with</p>

<pre><code>return [x for x in a if -x in a]
</code></pre>

<p>I'm just having problems implementing a set into the problem.
Can someone give me the steps to take, how I should tackle the problem... I'm not looking for the complete work, but it would be nice to see how you do it also.</p>
