title: Parsing xml with lxml in python 3
body: <p>I have this code, i want to group animals with the same tags to the one group ex. tags<code>&lt;dog&gt;&lt;dog&gt;</code> to <code>&lt;dogs&gt;&lt;dog/&gt;&lt;dog/&gt;&lt;/dogs&gt;</code> etc. But in my code, I have no idea why is the output without animals.</p>
  
  <p>OUTPUT:</p>
  
  <pre><code>&lt;root&gt;
         &lt;zoo&gt;
             &lt;some_tag/&gt;&lt;some_diff/&gt;
         &lt;/zoo&gt;
         &lt;zoo&gt;
             &lt;b/&gt;&lt;o/&gt;
         &lt;/zoo&gt;
   &lt;/root&gt;
  </code></pre>
  
  <p>CODE: </p>
  
  <pre><code> xml = '`&lt;root&gt;
                    &lt;zoo&gt;
                        &lt;some_tag/&gt;&lt;some_diff/&gt;
                        &lt;dog/&gt;&lt;dog/&gt;
                        &lt;cat/&gt;&lt;cat/&gt;&lt;cat/&gt;
                    &lt;/zoo&gt;
                    &lt;zoo&gt;
                        &lt;b/&gt;&lt;o/&gt;
                        &lt;dog/&gt;&lt;dog/&gt;
                        &lt;cat/&gt;&lt;cat/&gt;&lt;cat/&gt;&lt;cat/&gt;
                    &lt;/zoo&gt;
              &lt;/root&gt;`'
  
  from lxml import etree as et
  root = et.fromstring(xml)
  node = root.findall('./zoo')
  j = False
  k = False
  for zoo in node:
      for animal in zoo:
          if 'dog' in animal.tag:
              if not j:
                  dogs = et.SubElement(zoo,'dogs')
              dogs.append(animal)
              j = True
          if 'cat' in animal.tag:                        
              if not k:
                  cats = et.SubElement(zoo,'cats')            
              cats.append(animal)
              k = True
  
      k = False
      j= False  
  </code></pre>