title: Operate values within a list of lists Python
body: <p>I seek operating a list of lists as follows:</p>
  <pre><code>#          key
  example = [[2,   2, -10, 'Yes'],
             [2,   8,  21, 'Yes'],
             [2,  19,  14, 'Non'],
             [2,  30, -22, 'Non'],
             [4, -15,  31, 'Yes'],
             [4,   2,  17, 'Yes'],
             [4,   3, -90, 'Non']]
  
  
  # What I have tried through dictionaries 
  dictsum = dict()
  for i in example:
      if i[0] in dictsum.keys():
          if i[3] == &quot;Yes&quot;:
              dictsum[i[0]][0] = dictsum[i[0]][0]+i[1]
              dictsum[i[0]][1] = dictsum[i[0]][1]+i[2]
      else:
          dictsum[i[0]] = [i[1], i[2]]
          
  onlysum = [[k,v[0], v[1]] for k,v in dictsum.items()]        
  </code></pre>
  <p>As noted, all rows 'i[1]' and 'i[2]' have been added, respecting their key 'i[0]' and a conditional 'i[3]'.</p>
  <p>What I try to do is find the value furthest from zero if i[3] == &quot;Non&quot; and add that value respecting its corresponding key 'i[0]'</p>
  <p>Something should be like this:</p>
  <pre><code>result = [[2,   10 + 30,   11 +(-22)], 
            [4,   -13 + 3,   48 +(-90)]]
  
  # Finally
  result = [[2, 40, -11], 
            [4, -10, -42]]
  </code></pre>
  <p>I clarify that this is an example raised by myself to understand how the lists are operated in these cases, I am not an expert. If someone knows a way to give you a solution and feedback, I appreciate that you share it, cordial greetings.</p>