You are viewing a single comment's thread. Return to all comments →
from itertools import combinations_with_replacement
Reading input and splitting it into the string and integer r
s, r = input().split()
Sorting the string to ensure lexicographic order
s = sorted(s)
Generating and printing the combinations with replacement for combo in combinations_with_replacement(s, int(r)): print(''.join(combo))
Seems like cookies are disabled on this browser, please enable them to open this website
itertools.combinations_with_replacement()
You are viewing a single comment's thread. Return to all comments →
from itertools import combinations_with_replacement
Reading input and splitting it into the string and integer r
s, r = input().split()
Sorting the string to ensure lexicographic order
s = sorted(s)
Generating and printing the combinations with replacement for combo in combinations_with_replacement(s, int(r)): print(''.join(combo))