+ 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

10th Jan 2020, 1:32 PM
Vinay Kumar
Vinay Kumar - avatar
6 ответов
+ 1
Mihai Apostol I want detailed program. In order to understand way of implementation, not that function.
10th Jan 2020, 1:47 PM
Vinay Kumar
Vinay Kumar - avatar
10th Jan 2020, 1:36 PM
Mihai Apostol
Mihai Apostol - avatar
+ 2
You're welcome.
10th Jan 2020, 2:18 PM
Mihai Apostol
Mihai Apostol - avatar
0
Mihai Apostol thanks for your time and help😊
10th Jan 2020, 2:17 PM
Vinay Kumar
Vinay Kumar - avatar
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
15th Oct 2024, 4:23 PM
Dan 4izer
Dan 4izer - avatar