You are viewing a single comment's thread. Return to all comments →
from itertools import combinations
S, k = input().split() k = int(k)
S = ''.join(sorted(S))
for i in range(1, k + 1): for combo in combinations(S, i): print(''.join(combo))
Seems like cookies are disabled on this browser, please enable them to open this website
itertools.combinations()
You are viewing a single comment's thread. Return to all comments →
from itertools import combinations
Read input
S, k = input().split() k = int(k)
Sort the string to ensure lexicographic order
S = ''.join(sorted(S))
Generate and print combinations for each length from 1 to k
for i in range(1, k + 1): for combo in combinations(S, i): print(''.join(combo))