title: Sum of specific elements in a list, if they are consecutive (python)
body: <blockquote>
    <p>What question is asking for is, from a list of lists like the following, to return a tuple that contains tuples of all occurrences of the number 2 for a given index on the list. If there are X consecutive 2s, then it should appear only one element in the inside tuple containing X, just like this:</p>
  </blockquote>
  
  <pre><code>[[1, 2, 2, 1],
   [2, 1, 1, 2],
   [1, 1, 2, 2]]
  </code></pre>
  
  <p>Gives</p>
  
  <pre><code>((1,), (1,), (1, 1),(2,))
  </code></pre>
  
  <p>While </p>
  
  <pre><code>[[2, 2, 2, 2],
   [2, 1, 2, 2],
   [2, 2, 1, 2]]
  </code></pre>
  
  <p>Gives</p>
  
  <pre><code>((3,),(1, 1),(2,)(3,))
  </code></pre>
  
  <blockquote>
    <p>What about the same thing but not for the columns, this time, for the rows? is there a "one-line" method to do it? I mean:</p>
  </blockquote>
  
  <pre><code>[[1, 2, 2, 1],
   [2, 1, 1, 2],
   [1, 1, 2, 2]]
  </code></pre>
  
  <p>Gives</p>
  
  <pre><code>((2,), (1, 1), (2,))
  </code></pre>
  
  <p>While </p>
  
  <pre><code>[[2, 2, 2, 2],
   [2, 1, 2, 2],
   [2, 2, 1, 2]]
  </code></pre>
  
  <p>Gives</p>
  
  <pre><code>((4,),(1, 2),(2, 1))
  </code></pre>
  
  <p>I have tried some things, this is one of the things, I can't finish it, don't know what to do anymore, after it:</p>
  
  <pre><code>l = [[2,2,2],[2,2,2],[2,2,2]]
  t = (((1,1),(2,),(2,)),((2,),(2,),(1,1)))
  
  if [x.count(0) for x in l] == [0 for x in l]:
          espf = []*len(l)
          espf2 = []
          espf_atual = 0
          contador = 0
          for x in l:
              for c in x:
                  celula = x[c]
                  if celula == 2:
                      espf_atual += 1
                  else:
                      if celula == 1:
                          espf[contador] = [espf_atual]
                          contador += 1
                          espf_atual = 0
          espf2 += [espf_atual]
          espf_atual = 0
      print(tuple(espf2))
  </code></pre>
  
  <p>output
      (3, 3, 3)</p>
  
  <p>this output is the correct one but if I change the list(l) it doesn't work</p>