How can I generate a list of all possible permutations in range
up vote
2
down vote
favorite
I would like to generate words list in a specific way. I would like to find all permutations for my variable l='EDCMI' not only for 5 characters but for 4 characters, 3 characters etc.
python python-3.x for-loop permutation itertools
add a comment |
up vote
2
down vote
favorite
I would like to generate words list in a specific way. I would like to find all permutations for my variable l='EDCMI' not only for 5 characters but for 4 characters, 3 characters etc.
python python-3.x for-loop permutation itertools
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I would like to generate words list in a specific way. I would like to find all permutations for my variable l='EDCMI' not only for 5 characters but for 4 characters, 3 characters etc.
python python-3.x for-loop permutation itertools
I would like to generate words list in a specific way. I would like to find all permutations for my variable l='EDCMI' not only for 5 characters but for 4 characters, 3 characters etc.
python python-3.x for-loop permutation itertools
python python-3.x for-loop permutation itertools
edited Nov 22 at 9:53
asked Nov 21 at 23:51
progthematic
143
143
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
Just use a nested for
loop and remember to add 1 to your range argument to include permutations the same length as your input string:
from itertools import permutations
s = 'EDCMI'
for i in range(len(s) + 1):
for p in permutations(s, i):
print(''.join(p))
1
you have to start the range of your outer loop at 1 if you don't want the empty element''
– godot
Nov 22 at 0:11
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Just use a nested for
loop and remember to add 1 to your range argument to include permutations the same length as your input string:
from itertools import permutations
s = 'EDCMI'
for i in range(len(s) + 1):
for p in permutations(s, i):
print(''.join(p))
1
you have to start the range of your outer loop at 1 if you don't want the empty element''
– godot
Nov 22 at 0:11
add a comment |
up vote
3
down vote
accepted
Just use a nested for
loop and remember to add 1 to your range argument to include permutations the same length as your input string:
from itertools import permutations
s = 'EDCMI'
for i in range(len(s) + 1):
for p in permutations(s, i):
print(''.join(p))
1
you have to start the range of your outer loop at 1 if you don't want the empty element''
– godot
Nov 22 at 0:11
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Just use a nested for
loop and remember to add 1 to your range argument to include permutations the same length as your input string:
from itertools import permutations
s = 'EDCMI'
for i in range(len(s) + 1):
for p in permutations(s, i):
print(''.join(p))
Just use a nested for
loop and remember to add 1 to your range argument to include permutations the same length as your input string:
from itertools import permutations
s = 'EDCMI'
for i in range(len(s) + 1):
for p in permutations(s, i):
print(''.join(p))
answered Nov 21 at 23:54
jpp
84.8k194897
84.8k194897
1
you have to start the range of your outer loop at 1 if you don't want the empty element''
– godot
Nov 22 at 0:11
add a comment |
1
you have to start the range of your outer loop at 1 if you don't want the empty element''
– godot
Nov 22 at 0:11
1
1
you have to start the range of your outer loop at 1 if you don't want the empty element
''
– godot
Nov 22 at 0:11
you have to start the range of your outer loop at 1 if you don't want the empty element
''
– godot
Nov 22 at 0:11
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422054%2fhow-can-i-generate-a-list-of-all-possible-permutations-in-range%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown