1

I am tasked with a task of finding out the fastest way to find out all the possible subsequence of a string in Python. I did some googling and i found this solution:

def get_powerset (string):
    perm = []
    if len(string) == 0:
        perm.append("")
        return perm
    first = string[0]
    print ("first = " + str(first))
    rem = string[1:len(string)]
    print ("rem = " + str(rem))
    words = get_powerset(rem)
    perm.extend(words)
    for word in words:
        perm.append(first+word)

    return perm

But i could not understand the logic behind it. Can someone please let me know if this is the best solution, or is there a better and faster way to do it.

Also kindly explain your answer so that i can understand the logic behind it.

Thanks in advance.

Subhayan Bhattacharya
  • 5,407
  • 7
  • 42
  • 60
  • Possible duplicate of [Please explain this algorithm to get all permutations of a String](http://stackoverflow.com/questions/14008521/please-explain-this-algorithm-to-get-all-permutations-of-a-string) and [python recursion permutations](http://stackoverflow.com/questions/13109274/python-recursion-permutations) and [understanding recursion permutations Python](http://stackoverflow.com/questions/41927240/understanding-recursionpermutations-python) – TessellatingHeckler Apr 23 '17 at 05:27

0 Answers0