title: Generating combinations of two strings using Python
body: <p>I have a string str1 = "ABC" and I need to insert 0 to len(str1) number of "x"s in the string str1 except at the last position. </p>
  
  <p>So in the above example, I want a resultant list with 0 to 2 "x"s placed before or inside the string which looks like </p>
  
  <pre><code>["ABC",
   "xABC",
   "AxBC",
   "ABxC",
   "xxABC",
   "xAxBC",
   "xABxC",
   "AxxBC",
   "AxBxC",
   "ABxxC"]
  </code></pre>
  
  <p>I tried some code which is as follows (I do realize that I have missed out few combinations in this):</p>
  
  <pre><code>&gt;&gt;&gt; for i in range(1, len(str1)):
  ...     for k in range(len(str1)):
  ...         str1[:k]+"x"*i+str1[k:]
  ... 
  'xABC'
  'AxBC'
  'ABxC'
  'xxABC'
  'AxxBC'
  'ABxxC'
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>I am not really sure about how to approach the other case with inter-leavings between the two for e.g. xAxBC etc</p>
  
  <p>What is the best approach to solve this?</p>