title: Getting all combinations of a string and its substrings
body: <p>I've seen many questions on getting all the possible substrings (i.e., adjacent sets of characters), but none on generating all possible strings including the combinations of its substrings.</p>
  
  <p>For example, let:</p>
  
  <pre><code>x = 'abc'
  </code></pre>
  
  <p>I would like the output to be something like:</p>
  
  <pre><code>['abc', 'ab', 'ac', 'bc', 'a', 'b', 'c']
  </code></pre>
  
  <p>The main point is that we can remove multiple characters that are not adjacent in the original string (as well as the adjacent ones).</p>
  
  <p>Here is what I have tried so far:</p>
  
  <pre><code>def return_substrings(input_string):
      length = len(input_string)
      return [input_string[i:j + 1] for i in range(length) for j in range(i, length)]
  
  print(return_substrings('abc'))
  </code></pre>
  
  <p>However, this only removes sets of adjacent strings from the original string, and will not return the element <code>'ac'</code> from the example above.</p>
  
  <p>Another example is if we use the string <code>'abcde'</code>, the output list should contain the elements <code>'ace'</code>, <code>'bd'</code> etc.</p>