We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
s = input().split()
x = s[0]
y = int(s[1])
sorted_s = sorted(x)
for i in range(1,y+1):
# for j in permutations(sorted_s,i):
# for j in range(len(sorted_s)):
# for j in permutations(sorted_s):
for j in permutations(sorted_s,i+1):
if i>=2:
continue
print(''.join(j))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
itertools.permutations()
You are viewing a single comment's thread. Return to all comments →
from itertools import permutations
s = input().split() x = s[0] y = int(s[1]) sorted_s = sorted(x)
for i in range(1,y+1): # for j in permutations(sorted_s,i): # for j in range(len(sorted_s)): # for j in permutations(sorted_s): for j in permutations(sorted_s,i+1): if i>=2: continue print(''.join(j))