find all possible combinations of letters in a string in python
Question: I have a string in python, I need to find all the possible ways any substring
of that string (including itself) could be selected. A substring (for my
purposes) does not have to be contiguous, in the original string -- it could
have gaps.  
Eg "frogman" is one of the many substrings of "froghuman' under this
definition.

For example of the would function: If my string is `"abcd"`, the output should
be:

    
    
    ["a","b","c","d","ab","ac","ad","bc","bd","cd","abc","abd","acd","bcd","abcd"]
    


Answer: Your example input/output suggests that you are looking for a [power
set](http://en.wikipedia.org/wiki/Power_set). You could [generate a power set
for a string using `itertools` module in
Python](https://docs.python.org/dev/library/itertools.html#itertools-recipes):

    
    
    from itertools import chain, combinations
    
    def powerset(iterable):
        "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
        s = list(iterable)
        return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
    
    print(list(map(''.join, powerset('abcd'))))
    

### Output

    
    
    ['',
     'a',
     'b',
     'c',
     'd',
     'ab',
     'ac',
     'ad',
     'bc',
     'bd',
     'cd',
     'abc',
     'abd',
     'acd',
     'bcd',
     'abcd']
    

Note: the output includes the empty string.

