In this HackerRank itertools.combinations_with_replacement() problem solution you are given a string S and your task is to print all possible size k replacement combinations of string in lexicographically sorted order.

HackerRank itertools.combinations_with_replacement() in python problem solution

HackerRank itertools.combinations_with_replacement() in python problem solution

# Enter your code here. Read input from STDIN. Print output to STDOUT
from itertools import combinations_with_replacement
a = raw_input().split()
w,c = a[0],int(a[1])
#print list(combinations_with_replacement(w,c))
for x in sorted(map(lambda x: ''.join(sorted(list(x))),list(combinations_with_replacement(w,c)))): print x