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.
Might be lengthy but easy to understand for beginners. Hope this helps:
fromitertoolsimportcombinationsS=input().split()#Splitsinputintoalistusingspacefrominputasseparatorstring=sorted(S[0])size=int(S[1])# Iterating combination size from 1 up to number specified in ki=1whilei<=size:comb=list(combinations(string,i))i+=1foritemincomb:print(''.join(item).replace(" ",""))
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 →
Might be lengthy but easy to understand for beginners. Hope this helps: