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.
Enter your code here. Read input from STDIN. Print output to STDOUT
from itertools import combinations
if name == "main":
s , k = input().split()
final_list=[]
for i in range(1,int(k)+1):
final=[]
result = list(combinations(s,i))
for x in result:
x = list(x)
x.sort()
final.append("".join(x))
final.sort()
final_list.extend(final)
print("\n".join(final_list))
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 →
Enter your code here. Read input from STDIN. Print output to STDOUT
from itertools import combinations if name == "main": s , k = input().split() final_list=[] for i in range(1,int(k)+1): final=[] result = list(combinations(s,i)) for x in result: x = list(x) x.sort() final.append("".join(x)) final.sort() final_list.extend(final)
print("\n".join(final_list))