Permutations python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Permutations python

How do I write all the possible permutations of ABC? So AAA, AAB,AAC,ABC,ABB,... With and without the same letter in a fragment for example ABC, ACB, BAC, BCA, CAB, CBA,.. so without AAA etc

1st Mar 2019, 10:41 PM
vicky
3 Answers
+ 2
from itertools import permutations for each in permutations('abc', 3): print(each) there is a permutations function in the itertools standard library, no need to re-create the wheel https://docs.python.org/3/library/itertools.html#itertools.permutations
1st Mar 2019, 11:15 PM
Steven M
Steven M - avatar
+ 1
here I did something similar, you can change this code a bit and get what you need https://code.sololearn.com/c5eOd7LLxyF4/?ref=app
1st Mar 2019, 10:49 PM
Before
Before - avatar
0
Before I don‘t know how to change
2nd Mar 2019, 9:02 PM
vicky