Missing permutation with itertools.permutations()2019 Community Moderator ElectionHow to generate all permutations of a list in Pythonpermutations with unique valuesPermutations in JavaScript?Permutation of an array, with repetition, in JavaGenerating permutations using BitmaskingItertools.permutations returns <object> instead of list of permutationsPermutation of a 2D arrayHow can I print the same list twice without empty it?Is there a better way to create permutations of string w bounded by length?Organizing rows following cartesian product of 3 columns in Pandas

Hotkey (or other quick way) to insert a keyframe for only one component of a vector-valued property?

Virginia employer terminated employee and wants signing bonus returned

What Happens when Passenger Refuses to Fly Boeing 737 Max?

Should I tell my boss the work he did was worthless

How many characters using PHB rules does it take to be able to have access to any PHB spell at the start of an adventuring day?

Is it "Vierergruppe" or "Viergruppe", or is there a distinction?

Vocabulary for giving just numbers, not a full answer

Are babies of evil humanoid species inherently evil?

Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?

Is it possible to avoid unpacking when merging Association?

Can one live in the U.S. and not use a credit card?

Why doesn't this Google Translate ad use the word "Translation" instead of "Translate"?

What wound would be of little consequence to a biped but terrible for a quadruped?

How can I ensure my trip to the UK will not have to be cancelled because of Brexit?

Error during using callback start_page_number in lualatex

Can Mathematica be used to create an Artistic 3D extrusion from a 2D image and wrap a line pattern around it?

Why does the negative sign arise in this thermodynamic relation?

Should I take out a loan for a friend to invest on my behalf?

They call me Inspector Morse

Can I pump my MTB tire to max (55 psi / 380 kPa) without the tube inside bursting?

Filtering SOQL results with optional conditionals

Why is computing ridge regression with a Cholesky decomposition much quicker than using SVD?

Do I really need to have a scientific explanation for my premise?

Database Backup for data and log files



Missing permutation with itertools.permutations()



2019 Community Moderator ElectionHow to generate all permutations of a list in Pythonpermutations with unique valuesPermutations in JavaScript?Permutation of an array, with repetition, in JavaGenerating permutations using BitmaskingItertools.permutations returns <object> instead of list of permutationsPermutation of a 2D arrayHow can I print the same list twice without empty it?Is there a better way to create permutations of string w bounded by length?Organizing rows following cartesian product of 3 columns in Pandas










0















I was solving the itertools.permutations() code on Hackerrank at https://www.hackerrank.com/challenges/itertools-permutations/problem and I came up with the following very simple code:



from itertools import permutations

to_perm, length = raw_input().split()
length = int(length)

res = permutations(to_perm, length)
new_res = []

for i in res:
new_res = sorted(res)

for i in new_res:
print "".join(i)


This is what I get as output:



AC
AH
AK
CA
CH
CK
HC
HK
KA
KC
KH


And this is my expected output:



AC
AH
AK
CA
CH
CK
HA
HC
HK
KA
KC
KH


You'll notice that I'm missing the permutation 'HA'.



My question is : Why am I missing this single permutation? And how can I solve this?










share|improve this question







New contributor




GourabIX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • If you print permutations(to_perm, length) then HA is there. I'm not sure why you sort res over and over again (and overwriting new_res)

    – DeepSpace
    Mar 6 at 15:39












  • @DeepSpace I sort res only once because the problem requires the printed result to be sorted lexicographically.

    – GourabIX
    Mar 7 at 5:49











  • It's been 2 days already. Can you guide me as to how to get more people to notice this? Most of the views on this page are by me only.

    – GourabIX
    Mar 8 at 6:17















0















I was solving the itertools.permutations() code on Hackerrank at https://www.hackerrank.com/challenges/itertools-permutations/problem and I came up with the following very simple code:



from itertools import permutations

to_perm, length = raw_input().split()
length = int(length)

res = permutations(to_perm, length)
new_res = []

for i in res:
new_res = sorted(res)

for i in new_res:
print "".join(i)


This is what I get as output:



AC
AH
AK
CA
CH
CK
HC
HK
KA
KC
KH


And this is my expected output:



AC
AH
AK
CA
CH
CK
HA
HC
HK
KA
KC
KH


You'll notice that I'm missing the permutation 'HA'.



My question is : Why am I missing this single permutation? And how can I solve this?










share|improve this question







New contributor




GourabIX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • If you print permutations(to_perm, length) then HA is there. I'm not sure why you sort res over and over again (and overwriting new_res)

    – DeepSpace
    Mar 6 at 15:39












  • @DeepSpace I sort res only once because the problem requires the printed result to be sorted lexicographically.

    – GourabIX
    Mar 7 at 5:49











  • It's been 2 days already. Can you guide me as to how to get more people to notice this? Most of the views on this page are by me only.

    – GourabIX
    Mar 8 at 6:17













0












0








0








I was solving the itertools.permutations() code on Hackerrank at https://www.hackerrank.com/challenges/itertools-permutations/problem and I came up with the following very simple code:



from itertools import permutations

to_perm, length = raw_input().split()
length = int(length)

res = permutations(to_perm, length)
new_res = []

for i in res:
new_res = sorted(res)

for i in new_res:
print "".join(i)


This is what I get as output:



AC
AH
AK
CA
CH
CK
HC
HK
KA
KC
KH


And this is my expected output:



AC
AH
AK
CA
CH
CK
HA
HC
HK
KA
KC
KH


You'll notice that I'm missing the permutation 'HA'.



My question is : Why am I missing this single permutation? And how can I solve this?










share|improve this question







New contributor




GourabIX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I was solving the itertools.permutations() code on Hackerrank at https://www.hackerrank.com/challenges/itertools-permutations/problem and I came up with the following very simple code:



from itertools import permutations

to_perm, length = raw_input().split()
length = int(length)

res = permutations(to_perm, length)
new_res = []

for i in res:
new_res = sorted(res)

for i in new_res:
print "".join(i)


This is what I get as output:



AC
AH
AK
CA
CH
CK
HC
HK
KA
KC
KH


And this is my expected output:



AC
AH
AK
CA
CH
CK
HA
HC
HK
KA
KC
KH


You'll notice that I'm missing the permutation 'HA'.



My question is : Why am I missing this single permutation? And how can I solve this?







python-2.7 permutation itertools






share|improve this question







New contributor




GourabIX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




GourabIX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




GourabIX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Mar 6 at 15:20









GourabIXGourabIX

312




312




New contributor




GourabIX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





GourabIX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






GourabIX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • If you print permutations(to_perm, length) then HA is there. I'm not sure why you sort res over and over again (and overwriting new_res)

    – DeepSpace
    Mar 6 at 15:39












  • @DeepSpace I sort res only once because the problem requires the printed result to be sorted lexicographically.

    – GourabIX
    Mar 7 at 5:49











  • It's been 2 days already. Can you guide me as to how to get more people to notice this? Most of the views on this page are by me only.

    – GourabIX
    Mar 8 at 6:17

















  • If you print permutations(to_perm, length) then HA is there. I'm not sure why you sort res over and over again (and overwriting new_res)

    – DeepSpace
    Mar 6 at 15:39












  • @DeepSpace I sort res only once because the problem requires the printed result to be sorted lexicographically.

    – GourabIX
    Mar 7 at 5:49











  • It's been 2 days already. Can you guide me as to how to get more people to notice this? Most of the views on this page are by me only.

    – GourabIX
    Mar 8 at 6:17
















If you print permutations(to_perm, length) then HA is there. I'm not sure why you sort res over and over again (and overwriting new_res)

– DeepSpace
Mar 6 at 15:39






If you print permutations(to_perm, length) then HA is there. I'm not sure why you sort res over and over again (and overwriting new_res)

– DeepSpace
Mar 6 at 15:39














@DeepSpace I sort res only once because the problem requires the printed result to be sorted lexicographically.

– GourabIX
Mar 7 at 5:49





@DeepSpace I sort res only once because the problem requires the printed result to be sorted lexicographically.

– GourabIX
Mar 7 at 5:49













It's been 2 days already. Can you guide me as to how to get more people to notice this? Most of the views on this page are by me only.

– GourabIX
Mar 8 at 6:17





It's been 2 days already. Can you guide me as to how to get more people to notice this? Most of the views on this page are by me only.

– GourabIX
Mar 8 at 6:17












1 Answer
1






active

oldest

votes


















0














I'm not sure what happens to HA in your code. This code outputs the correct result:



from itertools import permutations

to_perm, length = 'HACK', 2

res = permutations(to_perm, length)

res = sorted(res)

for perm in res:
print ''.join(perm)


Outputs



AC
AH
AK
CA
CH
CK
HA
HC
HK
KA
KC
KH





share|improve this answer























  • This works! Thanks a lot @DeepSpace ! :)

    – GourabIX
    Mar 8 at 17:25










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






GourabIX is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55026485%2fmissing-permutation-with-itertools-permutations%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I'm not sure what happens to HA in your code. This code outputs the correct result:



from itertools import permutations

to_perm, length = 'HACK', 2

res = permutations(to_perm, length)

res = sorted(res)

for perm in res:
print ''.join(perm)


Outputs



AC
AH
AK
CA
CH
CK
HA
HC
HK
KA
KC
KH





share|improve this answer























  • This works! Thanks a lot @DeepSpace ! :)

    – GourabIX
    Mar 8 at 17:25















0














I'm not sure what happens to HA in your code. This code outputs the correct result:



from itertools import permutations

to_perm, length = 'HACK', 2

res = permutations(to_perm, length)

res = sorted(res)

for perm in res:
print ''.join(perm)


Outputs



AC
AH
AK
CA
CH
CK
HA
HC
HK
KA
KC
KH





share|improve this answer























  • This works! Thanks a lot @DeepSpace ! :)

    – GourabIX
    Mar 8 at 17:25













0












0








0







I'm not sure what happens to HA in your code. This code outputs the correct result:



from itertools import permutations

to_perm, length = 'HACK', 2

res = permutations(to_perm, length)

res = sorted(res)

for perm in res:
print ''.join(perm)


Outputs



AC
AH
AK
CA
CH
CK
HA
HC
HK
KA
KC
KH





share|improve this answer













I'm not sure what happens to HA in your code. This code outputs the correct result:



from itertools import permutations

to_perm, length = 'HACK', 2

res = permutations(to_perm, length)

res = sorted(res)

for perm in res:
print ''.join(perm)


Outputs



AC
AH
AK
CA
CH
CK
HA
HC
HK
KA
KC
KH






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 8 at 10:29









DeepSpaceDeepSpace

39.5k44777




39.5k44777












  • This works! Thanks a lot @DeepSpace ! :)

    – GourabIX
    Mar 8 at 17:25

















  • This works! Thanks a lot @DeepSpace ! :)

    – GourabIX
    Mar 8 at 17:25
















This works! Thanks a lot @DeepSpace ! :)

– GourabIX
Mar 8 at 17:25





This works! Thanks a lot @DeepSpace ! :)

– GourabIX
Mar 8 at 17:25












GourabIX is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















GourabIX is a new contributor. Be nice, and check out our Code of Conduct.












GourabIX is a new contributor. Be nice, and check out our Code of Conduct.











GourabIX is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55026485%2fmissing-permutation-with-itertools-permutations%23new-answer', 'question_page');

);

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







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко