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.