title: How to modify last element of a generator in python?
body: <p>I have a generator and I want to modify the last element of the generator.
  I want to replace the last element with another element. I know how to retrieve the last element, but not how to modify it.</p>
  
  <p>What would be the best way to approach this?</p>
  
  <p>For more context, this is what I want to do:</p>
  
  <pre><code>for child in alexnet.children():
      for children_of_child in child.children():
           print(children_of_child);
  </code></pre>
  
  <p>My generator object is: <code>children_of_child</code> and for the second child all its children are:</p>
  
  <pre><code>Dropout(p=0.5)
  Linear(in_features=9216, out_features=4096, bias=True)
  ReLU(inplace)
  Dropout(p=0.5)
  Linear(in_features=4096, out_features=4096, bias=True)
  ReLU(inplace)
  Linear(in_features=4096, out_features=1000, bias=True)
  </code></pre>
  
  <p>I want to replace the last layer <code>Linear(in_features=4096, out_features=1000, bias=True)</code> with my own regression net. `</p>