title: Generate every possible subset of length 1..n of list/string
body: <p><strong>Problem</strong></p>
  
  <p>I have a string, for which I want to find every possible subset of lengths 1..n.</p>
  
  <p><strong>Example</strong></p>
  
  <p>Given the string "abc" and <code>n=3</code>, I want to produce the following list:</p>
  
  <p><code>{"a", "b", "c", "aa", "ab", "ac", "ba", ..., "aaa", "aab", "aac", "aba" ..., "ccc"}</code></p>
  
  <p><strong>My attempt</strong></p>
  
  <p>...is painfully novice. One loop for every <code>n</code>, nested <code>n</code> times.</p>
  
  <p>For n = 3, I'd have:</p>
  
  <pre><code>characters = "abcdef" # and so on
  
  for char in characters:
      print(char)
  
  for char1 in characters:
      for char2 in characters:
          print(str(char1) + str(char2))
  
  for char1 in characters:
      for char2 in characters:
          for char3 in characters:
              print(str(char1) + str(char2) + str(char3))
  </code></pre>
  
  <p>As you can see, this is unscalable to say the least. Is there a nice way to do this? Any complexity reductions would also be cool, although I have a hard time imagining any.</p>