title: Replace elements in list - with a nested list containing said elements (python3)
body: <p>I am trying to replace elements in a list with a list containig said elements, for example:</p>
  <pre><code>list = ['cow','orange','apple','mango']
  to_replace = 'orange', 'apple'
  replace_with = ['banana','cream']
  </code></pre>
  <p>Desired output:</p>
  <pre><code>['cow', ['banana', 'cream'], 'mango']
  </code></pre>
  <p>I've read the answers in this question <a href="https://stackoverflow.com/questions/39440360/replacing-an-item-in-list-with-items-of-another-list-without-using-dictionaries">1</a> and tried the function mentioned there:</p>
  <pre><code>def replace_item(list, to_replace, replace_with):
      for n,i in enumerate(list):
        if i== to_replace:
           list[n]=replace_with
      return list
  </code></pre>
  <p>but it does nothing. I also tried a basic equality functions:</p>
  <pre><code>list[1:3] = ['banana','cream']
  </code></pre>
  <p>However neither work. Is there a function to accomplish this? In my actual problem which is a loop, <code>list[1:3]</code> is an iterator, i.e. <code>list[i:i+2]</code>. I am not sure if this makes a difference. The items to be replaced will always be sequential.</p>