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.
def permutation():
user_input = input()
input_list = user_input.split()
var1, k = input_list[0], int(input_list[1])
sorted_var1 = "".join(sorted(var1))
for size in range(1, k + 1):
for combo in combinations(sorted_var1, size):
print("".join(combo))
if name == "main":
permutation()
Cookie support is required to access HackerRank
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
def permutation(): user_input = input() input_list = user_input.split() var1, k = input_list[0], int(input_list[1]) sorted_var1 = "".join(sorted(var1)) for size in range(1, k + 1): for combo in combinations(sorted_var1, size): print("".join(combo))
if name == "main": permutation()