title: How to get all possible subset of the string in python
body: <p>I have a case in which I want to generate all possible subset or the combination of the given string. so far I tried this:</p>
  
  <pre><code>def list_string(str):
     level=['']
     if len(str) &lt;=1:
         level += str
         return level
     else:
        for item in range(len(str)):
            n_list=[]
            for item1 in level:
                n_list.append(item1 + str[item])
            level += n_list
           . return level
  </code></pre>
  
  <p>so if I call
  print list_string('ab')</p>
  
  <p>I get only ['', 'a', 'b', 'ab'] I am missing 'ba' in the list.
  can anyone tell me where I am doing wrong.
  I want to do this without using itertools or modules.</p>