Function that returns a list of the count of positive numbers and sum of negative numbers
<p>I have a problem when I ran my code against the unit test. Any advice would be appreciated. Please find the code below:</p>

<pre><code>def manipulate_data(data):
    count = 0
    sum1 = 0
    new_list = []
    for x in data:
        if x &gt; 0:
            count += 1

        if x &lt; 0:
            sum1 += x

    new_list.append(count)
    new_list.append(sum1)

    return new_list
</code></pre>

<p>The unit test is below:</p>

<pre><code>import unittest

class ManipulateDataTestCases(unittest.TestCase):
  def test_only_lists_allowed(self):
    result = manipulate_data({})
    self.assertEqual(result, 'Only lists allowed', msg='Invalid argument')

  def test_it_returns_correct_output_with_positives(self):
    result = manipulate_data([1, 2, 3, 4])
    self.assertEqual(result, [4, 0], msg='Invalid output')

  def test_returns_correct_ouptut_with_negatives(self):
    result = manipulate_data([1, -9, 2, 3, 4, -5]);
    self.assertEqual(result, [4, -14], msg='Invalid output')
</code></pre>

<p>The error I get is:</p>

<pre class="lang-none prettyprint-override"><code>`Total Specs: 3 Total Failures: 1
  1 .  test_only_lists_allowed
  Failure in line 11, in test_only_lists_allowed
      self.assertEqual(result, 'Only lists allowed', msg='Invalid argument')
    AssertionError: Invalid argument`
</code></pre>

<p>Did you write your unit test?  The person who did thinks that you should only be checking lists.  The way to do this in python is:</p>

<pre><code>&gt;&gt;&gt;l = []
&gt;&gt;&gt;isinstance(l, list)
True
&gt;&gt;&gt;d = {}
&gt;&gt;&gt;isinstance(d, dict)
True
&gt;&gt;&gt;isinstance(d, list)
False
</code></pre>

<p>The way it's written, your program will attempt to iterate over all iterables, including <code>dict</code>.  If you want to keep this behavior, keep in mind that it will iterate over keys, not values, of a <code>dict</code>.</p>

python