title: Why does string.split('\n') adds an extra element in the output list?
body: <p>I have a list animals as below</p>
  
  <pre><code>animals = ['pets','dog\ncat\nchicken\ncow\n','wild','tiger\nlion\nrhino\n']
  </code></pre>
  
  <p>I want a separate list only for pets </p>
  
  <pre><code>pets = animals[1].split('\n')
  </code></pre>
  
  <p>print(pets) outputs ['dog', 'cat', 'chicken', 'cow', '']
  The last element of the pets list i.e '' is undesirable</p>
  
  <p>The line of code below removes the '' element from the list pets</p>
  
  <pre><code>pets = [i for i in animals[1].split('\n') if i]
  </code></pre>
  
  <p>Could you please explain why the former solution inserts '' in the list. Also, please clarify what is going on inside the list comprehension in the latter solution? what does "if i" represent?</p>