repeated more than once<\/em>.<\/p>\n\n\n\nCombinations are emitted in lexicographic sorted order. So, if the input iterable is sorted, the combination tuples will be produced in sorted order.<\/p>\n\n\n\n
Sample Code<\/strong><\/p>\n\n\n\n>>> from itertools import combinations_with_replacement\n>>> \n>>> print list(combinations_with_replacement('12345',2))\n[('1', '1'), ('1', '2'), ('1', '3'), ('1', '4'), ('1', '5'), ('2', '2'), ('2', '3'), ('2', '4'), ('2', '5'), ('3', '3'), ('3', '4'), ('3', '5'), ('4', '4'), ('4', '5'), ('5', '5')]\n>>> \n>>> A = [1,1,3,3,3]\n>>> print list(combinations(A,2))\n[(1, 1), (1, 3), (1, 3), (1, 3), (1, 3), (1, 3), (1, 3), (3, 3), (3, 3), (3, 3)]<\/code><\/pre>\n\n\n\n<\/span>Task<\/strong><\/span><\/h2>\n\n\n\nYou are given a string S<\/em><\/strong>.
Your task is to print all possible size k<\/em><\/strong> replacement combinations of the string in lexicographic sorted order.<\/p>\n\n\n\n<\/span>Input Format<\/strong><\/span><\/h2>\n\n\n\nA single line containing the string S<\/em><\/strong> and integer value k<\/em><\/strong> separated by a space.<\/p>\n\n\n\n<\/span>Constraints<\/strong><\/span><\/h2>\n\n\n\n- 0 < k<\/em> <= len<\/em>(S<\/em>)<\/strong><\/li>
- The string contains only UPPERCASE<\/em> characters.<\/li><\/ul>\n\n\n\n
<\/span>Output Format<\/strong><\/span><\/h2>\n\n\n\nPrint the combinations with their replacements of string S<\/em><\/strong> on separate lines.<\/p>\n\n\n\nSample Input<\/strong><\/p>\n\n\n\nHACK 2<\/code><\/pre>\n\n\n\nSample Output<\/strong><\/p>\n\n\n\nAA\nAC\nAH\nAK\nCC\nCH\nCK\nHH\nHK\nKK<\/code><\/pre>\n\n\n\n<\/span>Solution – Itertools.combinations_with_replacement()<\/strong><\/span><\/h2>\n\n\n\n# Enter your code here. Read input from STDIN. Print output to STDOUT\nfrom itertools import combinations_with_replacement\n\nS, k = map(str, input().split())\n\nS = sorted(S)\nk = int(k)\n\nfor e in list(combinations_with_replacement(S, k)):\n print(*e, sep='')<\/pre>\n\n\n\n