I am trying to get all the Subsequences of a String. Example:-
firstString = "ABCD"
O/P should be;
'ABCD', 'BCD', 'ACD', 'ABD', 'ABC', 'CD', 'BD', 'BC', 'AD', 'AC', 'AB', 'D', 'C', 'B', 'A'
For that I am using following part of code:-
#!usr/bin/python
from __future__ import print_function
from operator import itemgetter
from subprocess import call
import math
import itertools
import operator
call(["date"])
firstArray = []
firstString = "ABCD"
firstList = list(firstString)
for L in range(0, len(firstList)+1):
for subset in itertools.combinations(firstList, L):
firstArray.append(''.join(subset))
firstArray.reverse()
print (firstArray)
call(["date"])
But this code is not scalable.
If I provide :-
firstString = "ABCDABCDABCDABCDABCDABCDABCD"
The program takes almost 6 mins time to complete.
---------------- Capture while running the script --------------------
python sample-0012.py
Wed Feb 8 21:30:30 PST 2017
Wed Feb 8 21:30:30 PST 2017
Can someone please help?