+ 1
How to get all the combinations of a String (length=n)?
To find all possible combinations of letters in a string Eg. Input: abc Output: abc acb bac bca cab cba
6 Respuestas
+ 1
Mihai Apostol I want detailed program. In order to understand way of implementation, not that function.
+ 2
You're welcome.
0
0
Mihai Apostol thanks for your time and help😊
0
def vse_combinacii(m ):
a = [q for q in m]
def spisok_ostavshihsya_elementov(at, t):
a = ''
for q in at:
if a.count(q) < at.count(q) - t.count(q):
a += q
return a
while True:
if max([len(q) for q in a]) == len(m):
return a
for q in a:
for q1 in spisok_ostavshihsya_elementov(m,q):
a.append(q + q1)
a = [q for q in a if len(q) == max([len(q) for q in a])]
#m - string that you give as input